I am sure this question was asked in Stackoverflow, but I cannot find it, so you go.
Rust unboxed closures have anonymous types generated by the compiler. Therefore, there is no way to specify them in a signature type. This means that it is not possible to return unboxed closures by value.
The usual solution is to set the return value:
pub fn get_iter_names(&self) -> Box<Iterator<Item=???>> { Box::new(self.nodes.iter().cloned() .filter(|x| x.is_some()) .map(|x| x.unwrap().name)) }
You must specify any field of type name instead of ??? (I can't get it out of your code alone).
There is an RFC to allow the return of unboxed values ββthat implement some features, but is delayed. According to the discussion in this RFC PR, it seems that at least some work has been done lately, so it may be available in Rust (relatively) in the near future.
source share