I want to create generic structure with default type. But Rust compiler still requires me to specify explicit type when creating my structure.
struct A {}
struct C<T = A> {
t: Option<T>
}
fn main() {
let c = C { t: None };
}
Rust compiler shows this error:
error[E0282]: type annotations needed for `C<T>`
--> src/main.rs:8:9
|
8 | let c = C { t: None };
| - ^ cannot infer type for `T`
| |
| consider giving `c` the explicit type `C<T>`, where the type parameter `T` is specified
How can I allow user of my code to omit generic parameter?