How to take an IntoIterator of references and return a boxed Iterator of references to the modified values? - iterator

I've grasped the basics of Rust lifetimes and how to work with iterators in it, but still have troubles to define a function that takes an iterable of tuples and return an iterable of tuples also allocated on the heap.
(I know that "iterable" doesn't mean anything in Rust but I will still use it instead of IntoInterator)
use std::iter::{once, repeat};
fn foo<'a, I>(costs: I) -> Box<Iterator<Item = &'a (i32, f32)>>
where
I: IntoIterator<Item = &'a (usize, f32)>,
{
let preliminary_examination_costs = once(10.0).chain(repeat(20.0));
let id_assignment_costs = once(10.0).chain(repeat(20.0));
let batch_fixed = once(10.0).chain(repeat(0.0));
let temp: Vec<(usize, &(i32, f32))> = costs.into_iter().enumerate().collect();
temp.sort_by_key(|&(_, &(n, cost))| n);
Box::new(temp.into_iter().map(|(i, &(n, cost))| {
(
i,
cost + preliminary_examination_costs.next().unwrap()
+ id_assignment_costs.next().unwrap() + batch_fixed.next().unwrap(),
)
}))
}
(playground)
Here's the errors:
error[E0277]: the trait bound `std::vec::Vec<(usize, &(i32, f32))>: std::iter::FromIterator<(usize, &'a (usize, f32))>` is not satisfied
--> src/main.rs:10:73
|
10 | let temp: Vec<(usize, &(i32, f32))> = costs.into_iter().enumerate().collect();
| ^^^^^^^ a collection of type `std::vec::Vec<(usize, &(i32, f32))>` cannot be built from an iterator over elements of type `(usize, &'a (usize, f32))`
|
= help: the trait `std::iter::FromIterator<(usize, &'a (usize, f32))>` is not implemented for `std::vec::Vec<(usize, &(i32, f32))>`
error[E0271]: type mismatch resolving `<[closure#src/main.rs:12:35: 18:6 preliminary_examination_costs:_, id_assignment_costs:_, batch_fixed:_] as std::ops::FnOnce<((usize, &(i32, f32)),)>>::Output == &(i32, f32)`
--> src/main.rs:12:5
|
12 | / Box::new(temp.into_iter().map(|(i, &(n, cost))| {
13 | | (
14 | | i,
15 | | cost + preliminary_examination_costs.next().unwrap()
16 | | + id_assignment_costs.next().unwrap() + batch_fixed.next().unwrap(),
17 | | )
18 | | }))
| |_______^ expected tuple, found &(i32, f32)
|
= note: expected type `(usize, f32)`
found type `&(i32, f32)`
= note: required because of the requirements on the impl of `std::iter::Iterator` for `std::iter::Map<std::vec::IntoIter<(usize, &(i32, f32))>, [closure#src/main.rs:12:35: 18:6 preliminary_examination_costs:_, id_assignment_costs:_, batch_fixed:_]>`
= note: required for the cast to the object type `std::iter::Iterator<Item=&(i32, f32)>`

It's very useful to create a MCVE when encountering a problem, and it's something I encourage all learners to undertake. Here's one such MCVE that mirrors your code:
fn foo<'a, I>(costs: I) -> Box<Iterator<Item = &'a i32>>
where
I: IntoIterator<Item = &'a i32>,
{
Box::new(costs.into_iter().map(|i| i + 1))
}
error[E0271]: type mismatch resolving `<[closure#src/main.rs:5:36: 5:45] as std::ops::FnOnce<(&'a i32,)>>::Output == &i32`
--> src/main.rs:5:5
|
5 | Box::new(costs.into_iter().map(|i| i + 1))
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected i32, found &i32
|
= note: expected type `i32`
found type `&i32`
= note: required because of the requirements on the impl of `std::iter::Iterator` for `std::iter::Map<<I as std::iter::IntoIterator>::IntoIter, [closure#src/main.rs:5:36: 5:45]>`
= note: required for the cast to the object type `std::iter::Iterator<Item=&i32>`
You are accepting a reference then creating a brand new value based on the reference. That means that the return type is no longer a reference, thus your function signature is not upheld. You need to change it:
fn foo<'a, I>(costs: I) -> Box<Iterator<Item = i32>>
This will unlock another error because the compiler doesn't know enough about the concrete type of I::IntoIter:
error[E0310]: the associated type `<I as std::iter::IntoIterator>::IntoIter` may not live long enough
--> src/main.rs:6:5
|
6 | Box::new(costs.into_iter().map(|i| i + 1))
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= help: consider adding an explicit lifetime bound `<I as std::iter::IntoIterator>::IntoIter: 'static`...
note: ...so that the type `std::iter::Map<<I as std::iter::IntoIterator>::IntoIter, [closure#src/main.rs:6:36: 6:45]>` will meet its required lifetime bounds
--> src/main.rs:6:5
|
6 | Box::new(costs.into_iter().map(|i| i + 1))
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
We do as it suggests and add the 'static bound:
fn foo<'a, I>(costs: I) -> Box<Iterator<Item = i32>>
where
I: IntoIterator<Item = &'a i32>,
I::IntoIter: 'static,
{
Box::new(costs.into_iter().map(|i| i + 1))
}
See also:
Is there any way to return a reference to a variable created in a function?
error[E0277]: the trait bound `std::vec::Vec<(usize, &(i32, f32))>: std::iter::FromIterator<(usize, &'a (usize, f32))>` is not satisfied
This error is because you have an iterator of (usize, &'a (usize, f32)) and you are trying to make them into (usize, &(i32, f32)). You can't convert types like this.

Related

What's the appropriate way to return a reference to the value from a generic associated function?

Imagine a tiny map that stores 3 values, the first two for known keys. I'd like to implement an iterator for this map, but I'm running into lifetime issues. What's the appropriate way to return a reference to the value from a generic associated function (K::zero() in the example below)?
FYI, I own the trait, so I tried changing it to the new RFC195 associated const, which didn't help.
I've boiled down my problem to the following code:
extern crate num;
use num::*;
pub struct TinyMap<K: Num, V> {
v0: Option<V>, // value for K::zero()
v1: Option<V>, // value for K::one()
k2: K, // arbitrary K
v2: Option<V>, // value for k2
}
pub struct Iter<'a, K: 'a + Num, V: 'a> {
k0: K,
v0: &'a Option<V>,
v1: &'a Option<V>,
k2: &'a K,
v2: &'a Option<V>,
}
impl<K: Num, V> TinyMap<K, V> {
pub fn iter(&self) -> Iter<K, V> {
Iter {
k0: K::zero(),
v0: &self.v0,
v1: &self.v1,
k2: &self.k2,
v2: &self.v2,
}
}
}
impl<'a, K: 'a + Num, V: 'a> Iterator for Iter<'a, K, V> {
type Item = (&'a K, &'a V);
fn next(&mut self) -> Option<(&'a K, &'a V)> {
if (*self.v0).is_some() {
// code removed that remembers we did this once.
return Some((&self.k0, ((*self.v0).as_ref()).unwrap()));
}
// if (*self.v1).is_some() {
// code removed that remembers we did this once.
// return Some((&K::one(), &((*self.v1).unwrap())));
// }
None
}
}
error[E0495]: cannot infer an appropriate lifetime for borrow expression due to conflicting requirements
--> src/lib.rs:38:26
|
38 | return Some((&self.k0, ((*self.v0).as_ref()).unwrap()));
| ^^^^^^^^
|
note: first, the lifetime cannot outlive the anonymous lifetime #1 defined on the method body at 35:5...
--> src/lib.rs:35:5
|
35 | / fn next(&mut self) -> Option<(&'a K, &'a V)> {
36 | | if (*self.v0).is_some() {
37 | | // code removed that remembers we did this once.
38 | | return Some((&self.k0, ((*self.v0).as_ref()).unwrap()));
... |
44 | | None
45 | | }
| |_____^
note: ...so that reference does not outlive borrowed content
--> src/lib.rs:38:26
|
38 | return Some((&self.k0, ((*self.v0).as_ref()).unwrap()));
| ^^^^^^^^
note: but, the lifetime must be valid for the lifetime 'a as defined on the impl at 32:6...
--> src/lib.rs:32:6
|
32 | impl<'a, K: 'a + Num, V: 'a> Iterator for Iter<'a, K, V> {
| ^^
= note: ...so that the expression is assignable:
expected std::option::Option<(&'a K, &'a V)>
found std::option::Option<(&K, &V)>
It's not possible to do that with the Iterator trait, because of the lifetime of the self reference (which is elided away in your code, but can be explicitly written like this):
type Item = (&'a K, &'a V);
fn next<'s>(&'s mut self) -> Self::Item;
Since 's doesn't appear in the function's return value (and can't appear in there, because Self::Item can't use type parameters of the function), the output is not allowed to hold a reference to any of the iterator's member variables.
That's the mechanics of the mistake, now here's the why part:
Consider a function that does include a reference to a member of self, with all the lifetimes set up correctly:
struct SomeMember;
struct SomeObject {
some_member: SomeMember,
}
impl SomeObject {
fn some_function<'s>(&'s mut self) -> &'s SomeMember {
&self.some_member
}
}
The same way you're trying to return &self.k, but without any other things going on, and with the lifetimes fixed so that it's allowed. However, if I then try to do this:
fn main() {
let mut some_object = SomeObject{some_member: SomeMember};
let _item_1 = some_object.some_function();
let _item_2 = some_object.some_function();
}
error[E0499]: cannot borrow `some_object` as mutable more than once at a time
--> src/main.rs:15:23
|
14 | let _item_1 = some_object.some_function();
| ----------- first mutable borrow occurs here
15 | let _item_2 = some_object.some_function();
| ^^^^^^^^^^^ second mutable borrow occurs here
16 | }
| - first borrow ends here
The second call wasn't allowed, because it borrows some_object twice, mutably, a classic Rust no-no! But if I had tried to implement an iterator with an Item type that borrowed the iterator itself, then Iterator::collect() would be impossible, because it tries to pull more than one item out at once!
So, no, an iterator can't return an item that borrows its contents. That's an explicit, and intentional, part of the trait contract for iterators.
The consensus appears to be that as of this time (Rust 1.29), the only sensible way is to put K::zero() inside TinyMap. Thanks to #SvenMarnach for confirming my suspicions.

Iterating over a range of generic type

I have a trait
trait B {
type Index: Sized + Copy;
fn bounds(&self) -> (Self::Index, Self::Index);
}
I want to get all the Indexes within bounds:
fn iterate<T: B>(it: &T) {
let (low, high) = it.bounds();
for i in low..high {}
}
This won't work since there's no constraint that the type T can be "ranged" over, and the compiler says as much:
error[E0277]: the trait bound `<T as B>::Index: std::iter::Step` is not satisfied
--> src/main.rs:8:5
|
8 | for i in low..high {}
| ^^^^^^^^^^^^^^^^^^^^^ the trait `std::iter::Step` is not implemented for `<T as B>::Index`
|
= help: consider adding a `where <T as B>::Index: std::iter::Step` bound
= note: required because of the requirements on the impl of `std::iter::Iterator` for `std::ops::Range<<T as B>::Index>`
I tried adding the Step bound to Index
use std::iter::Step;
trait B {
type Index: Sized + Copy + Step;
fn bounds(&self) -> (Self::Index, Self::Index);
}
but apparently it isn't stable:
error: use of unstable library feature 'step_trait': likely to be replaced by finer-grained traits (see issue #42168)
--> src/main.rs:1:5
|
1 | use std::iter::Step;
| ^^^^^^^^^^^^^^^
error: use of unstable library feature 'step_trait': likely to be replaced by finer-grained traits (see issue #42168)
--> src/main.rs:4:32
|
4 | type Index: Sized + Copy + Step;
| ^^^^
Am I missing something or is it just not possible to do so right now?
If you want to require that a Range<T> can be iterated over, just use that as your trait bound:
trait Bounded {
type Index: Sized + Copy;
fn bounds(&self) -> (Self::Index, Self::Index);
}
fn iterate<T>(it: &T)
where
T: Bounded,
std::ops::Range<T::Index>: IntoIterator,
{
let (low, high) = it.bounds();
for i in low..high {}
}
fn main() {}
To do this kind of thing generically the num crate is helpful.
extern crate num;
use num::{Num, One};
use std::fmt::Debug;
fn iterate<T>(low: T, high: T)
where
T: Num + One + PartialOrd + Copy + Clone + Debug,
{
let one = T::one();
let mut i = low;
loop {
if i > high {
break;
}
println!("{:?}", i);
i = i + one;
}
}
fn main() {
iterate(0i32, 10i32);
iterate(5u8, 7u8);
iterate(0f64, 10f64);
}

How can I box the contents of an iterator of a type that implements a trait?

I'm taking an iterator of some type that must implement the trait A, and trying to convert it into a Vec of Boxes of that trait:
trait A {}
fn test2<'a, I>(iterator: I) -> Vec<Box<A + 'a>>
where
I: IntoIterator,
I::Item: A + 'a,
{
iterator
.into_iter()
.map(|a| Box::new(a))
.collect::<Vec<Box<A + 'a>>>()
}
However, this fails to compile, saying:
error[E0277]: the trait bound `std::vec::Vec<std::boxed::Box<A + 'a>>: std::iter::FromIterator<std::boxed::Box<<I as std::iter::IntoIterator>::Item>>` is not satisfied
--> src/main.rs:11:10
|
11 | .collect::<Vec<Box<A + 'a>>>()
| ^^^^^^^ a collection of type `std::vec::Vec<std::boxed::Box<A + 'a>>` cannot be built from an iterator over elements of type `std::boxed::Box<<I as std::iter::IntoIterator>::Item>`
|
= help: the trait `std::iter::FromIterator<std::boxed::Box<<I as std::iter::IntoIterator>::Item>>` is not implemented for `std::vec::Vec<std::boxed::Box<A + 'a>>`
= help: consider adding a `where std::vec::Vec<std::boxed::Box<A + 'a>>: std::iter::FromIterator<std::boxed::Box<<I as std::iter::IntoIterator>::Item>>` bound
This error kind of makes sense, but then I don't see why there's no problem with the following:
fn test<'a, T: A + 'a>(t: T) -> Box<A + 'a> {
Box::new(t)
}
How is that any different? How can I express that I'd like to Box them as As, rather than whatever type they may be?
You need to cast the Box<I::Item> into a Box<A>:
fn test2<'a, I>(iterator: I) -> Vec<Box<dyn A + 'a>>
where
I: IntoIterator,
I::Item: A + 'a,
{
iterator
.into_iter()
.map(|a| Box::new(a) as Box<dyn A>)
.collect()
}
How is [returning Box::new directly] any different?
As Sven Marnach points out:
The reason why you don't need an explicit cast in the function is that the last statement of a block is a coercion site and coercions happen implicitly at these sites. See the chapter on coercions in the nomicon for further details.

Extract chain of iterator calls to a helper function [duplicate]

This question already has answers here:
What is the correct way to return an Iterator (or any other trait)?
(2 answers)
Closed 5 years ago.
I'm trying to write a function that will encapsulate a series of chained iterator method calls (.lines().map(...).filter(...)) which I currently have duplicated. I can't figure out the type signatures to get this to compile. If this is impossible or highly unidiomatic for Rust, I'm open to suggestions for an idiomatic approach.
use std::fs;
use std::io;
use std::io::prelude::*;
use std::iter;
const WORDS_PATH: &str = "/usr/share/dict/words";
fn is_short(word: &String) -> bool {
word.len() < 7
}
fn unwrap(result: Result<String, io::Error>) -> String {
result.unwrap()
}
fn main_works_but_code_dupe() {
let file = fs::File::open(WORDS_PATH).unwrap();
let reader = io::BufReader::new(&file);
let count = reader.lines().map(unwrap).filter(is_short).count();
println!("{:?}", count);
let mut reader = io::BufReader::new(&file);
reader.seek(io::SeekFrom::Start(0));
let sample_size = (0.05 * count as f32) as usize; // 5% sample
// This chain of iterator logic is duplicated
for line in reader.lines().map(unwrap).filter(is_short).take(sample_size) {
println!("{}", line);
}
}
fn short_lines<'a, T>
(reader: &'a T)
-> iter::Filter<std::iter::Map<std::io::Lines<T>, &FnMut(&str, bool)>, &FnMut(&str, bool)>
where T: io::BufRead
{
reader.lines().map(unwrap).filter(is_short)
}
fn main_dry() {
let file = fs::File::open(WORDS_PATH).unwrap();
let reader = io::BufReader::new(&file);
let count = short_lines(reader).count();
println!("{:?}", count);
// Would like to do this instead:
let mut reader = io::BufReader::new(&file);
reader.seek(io::SeekFrom::Start(0));
let sample_size = (0.05 * count as f32) as usize; // 5% sample
for line in short_lines(reader).take(sample_size) {
println!("{}", line);
}
}
fn main() {
main_works_but_code_dupe();
}
I can't figure out the type signatures to get this to compile.
The compiler told you what it was.
error[E0308]: mismatched types
--> src/main.rs:35:5
|
35 | reader.lines().map(unwrap).filter(is_short)
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected reference, found fn item
|
= note: expected type `std::iter::Filter<std::iter::Map<_, &'a for<'r> std::ops::FnMut(&'r str, bool) + 'a>, &'a for<'r> std::ops::FnMut(&'r str, bool) + 'a>`
found type `std::iter::Filter<std::iter::Map<_, fn(std::result::Result<std::string::String, std::io::Error>) -> std::string::String {unwrap}>, for<'r> fn(&'r std::string::String) -> bool {is_short}>`
Now, granted, you can't just copy+paste this directly. You have to replace the _ type with the actual one you already had (it left it out because it was already correct). Secondly, you need to delete the {unwrap} and {is_short} bits; those are because function items have unique types, and that's how the compiler annotates them. Sadly, you can't actually write these types out.
Recompile and...
error[E0308]: mismatched types
--> src/main.rs:35:5
|
32 | -> std::iter::Filter<std::iter::Map<std::io::Lines<T>, fn(std::result::Result<std::string::String, std::io::Error>) -> std::string::String>, for<'r> fn(&'r std::string::String) -> bool>
| -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- expected `std::iter::Filter<std::iter::Map<std::io::Lines<T>, fn(std::result::Result<std::string::String, std::io::Error>) -> std::string::String>, for<'r> fn(&'r std::string::String) -> bool>` because of return type
...
35 | reader.lines().map(unwrap).filter(is_short)
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected fn pointer, found fn item
|
= note: expected type `std::iter::Filter<std::iter::Map<_, fn(std::result::Result<std::string::String, std::io::Error>) -> std::string::String>, for<'r> fn(&'r std::string::String) -> bool>`
found type `std::iter::Filter<std::iter::Map<_, fn(std::result::Result<std::string::String, std::io::Error>) -> std::string::String {unwrap}>, for<'r> fn(&'r std::string::String) -> bool {is_short}>`
Remember what I said about function items have unique types? Yeah, that. To fix that, we cast from a function item to a function pointer. We don't even need to specify what we're casting to, we just have to let the compiler know we want it to do a cast.
fn short_lines<'a, T>
(reader: &'a T)
-> std::iter::Filter<std::iter::Map<std::io::Lines<T>, fn(std::result::Result<std::string::String, std::io::Error>) -> std::string::String>, for<'r> fn(&'r std::string::String) -> bool>
where T: io::BufRead
{
reader.lines().map(unwrap as _).filter(is_short as _)
}
error[E0308]: mismatched types
--> src/main.rs:41:29
|
41 | let count = short_lines(reader).count();
| ^^^^^^ expected reference, found struct `std::io::BufReader`
|
= note: expected type `&_`
found type `std::io::BufReader<&std::fs::File>`
= help: try with `&reader`
Again, the compiler tells you exactly what to do. Make the change and...
error[E0507]: cannot move out of borrowed content
--> src/main.rs:35:5
|
35 | reader.lines().map(unwrap as _).filter(is_short as _)
| ^^^^^^ cannot move out of borrowed content
Right, that's because you got the input of short_lines wrong. One more change:
fn short_lines<T>
(reader: T)
-> std::iter::Filter<std::iter::Map<std::io::Lines<T>, fn(std::result::Result<std::string::String, std::io::Error>) -> std::string::String>, for<'r> fn(&'r std::string::String) -> bool>
where T: io::BufRead
{
reader.lines().map(unwrap as _).filter(is_short as _)
}
And now all you have to deal with are warnings.
In short: read the compiler messages. They're useful.
I'd suggest doing it the simple way - collecting the iterator into a vector:
use std::fs;
use std::io;
use std::io::prelude::*;
const WORDS_PATH: &str = "/usr/share/dict/words";
fn main() {
let file = fs::File::open(WORDS_PATH).unwrap();
let reader = io::BufReader::new(&file);
let short_lines = reader.lines()
.map(|l| l.unwrap())
.filter(|l| l.len() < 7)
.collect::<Vec<_>>(); // the element type can just be inferred
let count = short_lines.len();
println!("{:?}", count);
let sample_size = (0.05 * count as f32) as usize; // 5% sample
for line in &short_lines[0..sample_size] {
println!("{}", line);
}
}

Returning a boxed iterator over a value in a structure [duplicate]

This question already has answers here:
Why is adding a lifetime to a trait with the plus operator (Iterator<Item = &Foo> + 'a) needed?
(1 answer)
What is the correct way to return an Iterator (or any other trait)?
(2 answers)
Closed 5 years ago.
I want a function on a struct which returns an iterator to one of the struct's members. I tried something like the following, which doesn't work.
struct Foo {
bar: Vec<String>,
}
impl Foo {
fn baz(&self) -> Box<Iterator<Item = &String>> {
Box::new(self.bar.iter())
}
}
fn main() {
let x = Foo { bar: vec!["quux".to_string()] };
x.baz();
}
When compiling, I get the error below:
error[E0495]: cannot infer an appropriate lifetime for lifetime parameter in function call due to conflicting requirements
--> src/main.rs:7:27
|
7 | Box::new(self.bar.iter())
| ^^^^
|
note: first, the lifetime cannot outlive the anonymous lifetime #1 defined on the method body at 6:5...
--> src/main.rs:6:5
|
6 | / fn baz(&self) -> Box<Iterator<Item = &String>> {
7 | | Box::new(self.bar.iter())
8 | | }
| |_____^
note: ...so that reference does not outlive borrowed content
--> src/main.rs:7:18
|
7 | Box::new(self.bar.iter())
| ^^^^^^^^
= note: but, the lifetime must be valid for the static lifetime...
note: ...so that expression is assignable (expected std::boxed::Box<std::iter::Iterator<Item=&std::string::String> + 'static>, found std::boxed::Box<std::iter::Iterator<Item=&std::string::String>>)
--> src/main.rs:7:9
|
7 | Box::new(self.bar.iter())
| ^^^^^^^^^^^^^^^^^^^^^^^^^
I also tried adding lifetime information as suggested elsewhere
struct Foo {
bar: Vec<String>,
}
impl Foo {
fn baz<'a>(&self) -> Box<Iterator<Item = &String> + 'a> {
Box::new(self.bar.iter())
}
}
fn main() {
let x = Foo { bar: vec!["quux".to_string()] };
x.baz();
}
Now my error is the following:
error[E0495]: cannot infer an appropriate lifetime for lifetime parameter in function call due to conflicting requirements
--> src/main.rs:7:27
|
7 | Box::new(self.bar.iter())
| ^^^^
|
note: first, the lifetime cannot outlive the anonymous lifetime #1 defined on the method body at 6:5...
--> src/main.rs:6:5
|
6 | / fn baz<'a>(&self) -> Box<Iterator<Item = &String> + 'a> {
7 | | Box::new(self.bar.iter())
8 | | }
| |_____^
note: ...so that reference does not outlive borrowed content
--> src/main.rs:7:18
|
7 | Box::new(self.bar.iter())
| ^^^^^^^^
note: but, the lifetime must be valid for the lifetime 'a as defined on the method body at 6:5...
--> src/main.rs:6:5
|
6 | / fn baz<'a>(&self) -> Box<Iterator<Item = &String> + 'a> {
7 | | Box::new(self.bar.iter())
8 | | }
| |_____^
note: ...so that expression is assignable (expected std::boxed::Box<std::iter::Iterator<Item=&std::string::String> + 'a>, found std::boxed::Box<std::iter::Iterator<Item=&std::string::String>>)
--> src/main.rs:7:9
|
7 | Box::new(self.bar.iter())
| ^^^^^^^^^^^^^^^^^^^^^^^^^