|
|
|
|
|
by masklinn
3026 days ago
|
|
> But a string is a container In the same way unique_ptr is a container. > so string.deref() returns.... &str? Yes? &str::deref() also returns &str, Vec::deref() returns &[], Box<T>::deref() returns &T. That's literally how Deref is defined, Deref<Target=T>::deref() returns &T. *String returns str. > (FromStr vs From<&str>, .parse() vs .into()) These are not equivalent. From/Into are non-failing conversions, FromStr can fail. What you're looking for is TryFrom/TryInto which are still not done 2 years into the RFC: https://github.com/sfackler/rfcs/blob/try-from/text/0000-try... |
|
Typed that out too fast, yes, that's my problem. * String is one thing but String.deref() is another. But * is the dereference operator. Operator overloading ftw ;)
> What you're looking for is TryFrom/TryInto which are still not done 2 years into the RFC: https://github.com/sfackler/rfcs/blob/try-from/text/0000-try....
Sorry, yes, I actually opened an issue with my suggestions regarding that one with particular focus on the fallible vs infallible nature: https://github.com/rust-lang/rfcs/issues/2143