Basically, i wanted to provide an "extension method" for Options that returns true if a provided option is some, so i can use it like this: let res: Vec<Option<Nucleotide>> = element .to_uppercase() .chars() .map(Nucleotide::parse) .take_while(OptionExtensions::<Nucleotide>::is_some) <-- this is the desired usage .collect();
My first idea was to define a trait with default method, like this: first try
For this one, i get this error:
type annotations required: cannot resolve _: OptionExtensions<Nucleotide>
I cannot put the type parameter to anywhere where it would work.
However, if i create a "dummy" struct and put the same method to the impl block, like this: second try
It makes sense. The reason why i started thinking about my own implementation is that i thought i need to pass a "class" method (like in F#, for instance) to make it work.
I thought the library function fn is_some(&self) -> bool
doesn't count as a &Option<Nucleotide> -> bool