Skip to content

Owned RowIter/ColumnIter, Matrix::into_row_iter()/into_column_iter() #834

Open
@mankinskin

Description

@mankinskin

I am trying to move a matrix into an iterator over its rows or columns. row_iter() borrows the matrix, which breaks my usecase:

fn large_f<N, It: Iterator<Item=N>>(matrix_map: impl Fn(Matrix) -> It, mat: Matrix) { ... }

I need a a function that can map a matrix to an iterator for the same operations either on the matrix' rows or columns.

let mat = ...;
large_f(
    |mat| mat.row_iter(), // use rows
    mat);
large_fn(
    |mat| mat.column_iter(), // use columns
    mat);

But the error is:

251 |             |mat| mat.row_iter(),
    |                   ---^^^^^^^^^^^^^^^^^
    |                   |
    |                   returns a value referencing data owned by the current function
    |                   `mat` is borrowed here

So I would need something like into_row_iter() which moves out of mat.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions