I have a struct with generics like this:
struct Foo<T> {
member: Option<T>,
}
impl<T> Foo<T> {
pub fn new(member: Option<T>) -> Self {
Foo { member }
}
}
but when calling new
with None
, Rust cannot infer the type for T
:
let y = Foo::new(None);
19 | let y = Foo::new(None);
| - ^^^^^^^^ cannot infer type for type parameter `T`
| |
| consider giving `y` the explicit type `Foo<T>`, where the type parameter `T` is specified
but what type should I specify for this None
input? Here is my playground test.