if your rust function takes some type T: IntoIterator, and a caller passes a Box<dyn Iterator>, what's the effect of calling Box::new(arg.into_iter()) does it return the original box unmodified, unbox and rebox it, double-box it...?
-
Show this thread
-
I'm wondering if I'm incurring avoidable conversion costs by having some interfaces take overly-abstract types
2 replies 0 retweets 1 likeShow this thread -
so, IntoIterator has a blanket implementation for T: Iterator that just returns self, and Box<dyn Iterator> implements Iterator https://doc.rust-lang.org/src/core/iter/traits/collect.rs.html#242-249 …
1 reply 0 retweets 0 likesShow this thread -
so if I call Box::new(arg.into_iter()) do I get a double-boxed iterator?
1 reply 0 retweets 0 likesShow this thread -
-
Replying to @peidran
well except that if the compile only knows that arg: IntoIterator, it doesn't know the concrete type at runtime is Box<dyn Iterator>
1 reply 0 retweets 0 likes -
Replying to @mountain_ghosts
It's a single box. I think to find out what's "actually" happening you might have to look at the compiler output, which I don't know how to read. https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&gist=28ff79ba9f2f05a86bdd8fb2ff784c23 …
1 reply 0 retweets 0 likes -
Replying to @peidran
so I'm talking about a function of the kind of my_func here https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&gist=e9ebd97742a8519bd509cd94bd9a7b43 …
1 reply 0 retweets 0 likes
I'm a long way from Rust mastery, so I may be missing something, but I don't see how the function changes things. If you monomorphize the function and then inline it in main, it's the same code.
Loading seems to be taking a while.
Twitter may be over capacity or experiencing a momentary hiccup. Try again or visit Twitter Status for more information.