edit: minimal failure example
Rust play ground link: Rust Playground
use std::marker::PhantomData;
use std::iter::{Map, Enumerate};
pub struct Idx<T> {
idx: usize,
_t: PhantomData<T>,}
impl<T> Idx<T> {
pub fn new(x: usize) -> Idx<T> {
Idx {
idx: x,
_t: PhantomData::default()
}
}
}
pub struct Foo<T> {
pub(crate) m_data: Vec<T>,}
impl<T> Foo<T> {
pub fn enumerate_2(
&self,
) -> Map<Enumerate<std::slice::Iter<'_, T>>, impl Fn(usize, &T) -> (Idx<T>, &T)> {
let x = self
.m_data
.iter()
.enumerate()
.map(|(idx, x)| (Idx::new(idx), x));
x}}
original question
m._data: Vec<T>
pub fn enumerate_2(
&self,
) -> Map<Enumerate<std::slice::Iter<'_, T>>, Fn(usize, &T) -> (Idx<T>, &T)> {
let x = self
.m_data
.iter()
.enumerate()
.map(|(idx, x)| (Idx::new(idx), x));
x}
what is the compile error ?
57 | ) -> Map<Enumerate<std::slice::Iter<'_, T>>, Fn(usize, &T) -> (Idx<T>, &T)> {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time
|
= help: the trait `Sized` is not implemented for `(dyn for<'r> Fn(usize, &'r T) -> (table::Idx<T>, &T) + 'static)`
note: required by a bound in `Map`
why can't you add + Sized
?
57 | ) -> Map<Enumerate<std::slice::Iter<'_, T>>, Fn(usize, &T) -> (Idx<T>, &T) + Sized> {
| ----------------------------- ^^^^^ additional non-auto trait
| |
| first non-auto trait
|
= help: consider creating a new trait with all of these as super-traits and using that trait here instead: `trait NewTrait: for<'r> Fn<(usize, &'r T)> + Sized {}`
= note: auto-traits like `Send` and `Sync` are traits that have special properties; for more information on them, visit
why not just use impl DoubleEndedIterator<Item = (Idx<K>, &T)>
?
weird issues with IntelliJ type inference when used in for loop