I want to write something like this:
use std::{iter, ops}; struct Idx(usize); fn get_inds() -> iter::Zip<iter::Map<ops::RangeFrom<usize>, fn(usize) -> Idx>, ops::RangeFrom<usize>> { (0..).map(Idx).zip(0..) }
However, this does not compile:
error: mismatched types [--explain E0308] --> src/main.rs:6:9 6 |> (0..).map(Idx).zip(0..) |> ^^^^^^^^^^^^^^^^^^^^^^^ expected fn pointer, found fn item note: expected type `std::iter::Zip<std::iter::Map<std::ops::RangeFrom<usize>, fn(usize) -> Idx>, std::ops::RangeFrom<usize>>` note: found type `std::iter::Zip<std::iter::Map<std::ops::RangeFrom<usize>, fn(usize) -> Idx {Idx::{{constructor}}}>, std::ops::RangeFrom<_>>`
Then I will pass the function:
fn get_inds() -> iter::Zip<iter::Map<ops::RangeFrom<usize>, fn(usize) -> Idx>, ops::RangeFrom<usize>> { (0..).map(Idx as fn(usize) -> Idx).zip(0..) }
Which generates the following compiler warning. Why am I getting a warning? What is the correct way to use the constructor?
warning: can't cast this type, #[warn(const_err)] on by default --> src/main.rs:6:19 6 |> (0..).map(Idx as fn(usize) -> Idx).zip(0..) |> ^^^^^^^^^^^^^^^^^^^^^^^
dspyz source share