3 ms·
> To me, the parse() call seems the most volatile -- what guarantees are there that the bytes you just read are parsable? None, which is why, in Rust, parse ne
by maxwell86 5y ago
> To me, the parse() call seems the most volatile -- what guarantees are there that the bytes you just read are parsable?
None, which is why, in Rust, parse never throws an exception on a parsing error, and instead, returns a Result<Ok=T,Err=ParseError>, which is an ADT with either an Ok(T), which means parse succeeded, or an Err(ParseError), which means that an error happened, and contains state about where, etc.
See its documentation: https://doc.rust-lang.org/stable/std/primitive.str.html#method.parse https://doc.rust-lang.org/stable/std/primitive.str.html#meth...
The author isn't talking about this, probably cause its not the point of the article, but in Rust, you can't avoid handling parsing errors. If you want to actually get the value, you need to handle the possibility that an error happened. The programming model does not give the user a choice here.