I have a function
fn some_func(num: Option<u32>){
match num{
Some(val) => ....,
None => ....,
}
}
I want to call it like
some_func(3);
instead of
some_func(Some(3));
What is a good way to do this?
I tried to implement From<u32>
for Option<u32>
impl From<u32> for Option<u32> {
fn from(num: u32) -> Self {
Some(num)
}
}
But this show the error
conflicting implementations of trait std::convert::From<u32>
for type std::option::Option<u32>
:
conflicting implementation in crate core
:
- impl std::convert::From for std::option::Option;rustc(E0119)
only traits defined in the current crate can be implemented for arbitrary types
define and implement a trait or new type insteadrustc(E0117)
What can I do instead?
Or more generally speaking, what is the best way to represent optional parameters?