You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I tried to use the existing conversion provided by the ToOption<T> trait which Result<T,E> implements:
#[deriving(Clone)]structA;fnmain(){let a :Result<A,int> = Ok(A);
a.to_option();}
But apparently, the compiler does not find its implementation:
option.rs:6:4: 6:18 error: type `std::result::Result<A,int>` does not implement any method in scope named `to_option`
option.rs:6 a.to_option();
^~~~~~~~~~~~~~
error: aborting due to previous error
Maybe I've done something wrong but I'm rather dry on ideas right now...
The text was updated successfully, but these errors were encountered:
You need to add a use std::option::ToOption; to the top of the file. Methods defined by a trait are only callable if they're imported (some traits are implicitly imported in the prelude).
Ok I feel a bit dumb :), a re-read of the doc on traits and modules may be worth it.
On the other hand, it may be nice to have a visual help in the libstd docs to immediately see if a type/trait is re-exported by the prelude (or by another module maybe?). I'll try to look into rustdoc to see if this is doable.
flip1995
pushed a commit
to flip1995/rust
that referenced
this issue
May 20, 2023
I tried to use the existing conversion provided by the
ToOption<T>
trait whichResult<T,E>
implements:But apparently, the compiler does not find its implementation:
Maybe I've done something wrong but I'm rather dry on ideas right now...
The text was updated successfully, but these errors were encountered: