I'd like to make use of this function:
u8::from_str(src: &str) -> Result<u8, ParseIntError>
I can't seem to figure out the syntax to use it. This is what I am currently trying
use std::u8;
match u8::from_str("89") {
// Stuff...
}
I receive the following error:
error: unresolved name `u8::from_str`
What is the proper way to use functions that are defined in primitive modules?
Thanks in advance for any help!
The trick here is that
from_str
is actually part of the traitFromStr
. You need to use that trait, then specify which implementation you want to use:However, this particular concept has a more ergonomic option:
parse
:And you might be able to remove the
::<u8>
if something else constrains the type enough for it to be inferred.