In the following example, compiler will properly reject the code in the main function saying that "Trait "MyTrait1" is not implemented for type". However, in the first case, the type will be the expected "u32", but in the second the whole "Option".
script;
trait MyTrait1 {
fn foo();
}
fn bar<T>() -> Option<T> where T: MyTrait1 {
None
}
fn main(){
let x: Option<u32> = bar();
// ^^^ Trait "MyTrait1" is not implemented for type "u32". <<<--- OK: u32.
let x = bar::<Option<u32>>();
// ^^^^^^^^^^^^^^^^^^ Trait "MyTrait1" is not implemented for type "Option<u32>". <<<--- WRONG: Option<u32>.
}
In the following example, compiler will properly reject the code in the main function saying that "Trait "MyTrait1" is not implemented for type". However, in the first case, the type will be the expected "u32", but in the second the whole "Option".