Open
Description
It is not much work to implement TryFrom<&str>
for types implementing FromStr
, you can even generalize it;
impl<T> TryFrom<&str> for T
where
T: FromStr
{
type Error = T::Err;
fn try_from(input: &str) -> Result<Self, Self::Error> {
Self::from_str(input)
}
}
I don't think there is much of a reason to not implement it.
You might even be able to provide a more efficient implementation:
struct Hello<'a>(Cow<'a, str>);
impl FromStr for Hello<'static> {
fn from_str(input: &str) -> Result<Self, Self::Err> {
Ok(Self(Cow::Owned(input.into())))
}
}
impl<'a> TryFrom<&'a str> for Hello<'a> {
fn try_from(input: &'a str) -> Result<Self, Self::Error> {
Ok(Self(Cow::Borrowed(input)))
}
}