Why can I use the dyn Trait as the field type declaration inside the struct? I usually use &dyn trait, today I forgot put the & at the beginning of type when defining a struct. But rust doesn't complain it.
struct Test {
folder: dyn Iterator<Item = String>,
}
And I tried to make a new
method of it
impl Test {
fn new(folder: &dyn Iterator<Item = String>) -> Self {
Self { folder: *folder }
}
}
It gives me the error I expected that
| fn new(folder: &dyn Iterator<Item = String>) -> Self {
| ^^^^ doesn't have a size known at compile-time
But why doesn't Rust give an error when I define the struct before making the method for it? Does Rust know the size in the definition? Thanks.