Given the following struct Foo<T> that derives Default:
#[derive(Default)]
struct Foo<T> {
bar: Option<T>,
}
Why does this compile
fn create<T>() -> Foo<T> {
Foo {
bar: Option::default(),
}
}
but this doesn't?
fn create_alt<T>() -> Foo<T> {
Foo::default()
}
In my mind they are both doing the exact same thing--it shouldn't matter if T implements Default (which is what the compiler wants me to specify) because Option<T> implements Default.
Here is a link to the Rust Playground with this example.