-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Have From<&str> automatically provide FromStr #2143
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Comments
|
We're going to keep running into problems like this so long as rust doesn't have a way to resolve multiple implementation conflicts :/ Semantically, an infallible conversion is just a special case of fallible conversions, really just a Basically, replace Edit: corrected swapped |
Perhaps I'm reading this wrong, but if |
@DaseinPhaos Yes, that was a typo. Thanks for catching it - fixed. |
That approach isn't really actionable without breaking backwards compatibility. |
I'm not sure that's necessarily the case, @sfackler . Step 1) Make sure every struct that implements The important thing is that this happens before |
How is step 1 supposed to work? We don't own all Rust code in existence. |
I think I'm over complicating things. Make sure all current |
Taggging rust-lang/rust#33417 |
An important distinction between If I had been allowed to travel back in time and change something except not adding Also, I like |
I'm guessing this is blocked until specialization is stabilized ? Where something like this would be possible: impl<T> TryFrom<String> for T
where
T: FromStr,
{
type Error = <T as FromStr>::Err;
fn try_from(value: String) -> Result<Self, Self::Error> {
value.parse()
}
} |
@malobre yes, requires specialization. The impl you suggest is still in conflict because |
Currently rust has both the traits
std::str::FromStr
andstd::convert::From<T>
, the latter of which is often implemented forT: String
even whenstd::str::FromStr
is not.Can implementing
std::str::From<String>
/std::str::From<&str>
provide a free implementation ofstd::convert::FromStr
so that this problem is avoided?From<&str>
(being exception-free) can be used to implementFromStr
, even if the converse isn't true.The text was updated successfully, but these errors were encountered: