Closed as not planned
Description
Proposal
Implement the trait TryFrom<&'a str>
for numerical types, bool
and char
.
Problem statement
The given types implement the FromStr
trait; but that can't be used in contexts that require generic TryFrom
interface, which is the standard fallible conversion in Rust.
Motivation, use-cases
struct Dummy<T>(T);
impl<'a, T: TryFrom<&'a str>> TryFrom<&'a str> for Dummy<'a> {
type Error = T::Error;
fn try_from(s: &'a str) -> Result<Self, Error> {
Dummy(T::try_from(s)?)
}
}
Then, one could just do
let dummy: Dummy<u64> = s.try_into();
Solution sketches
Mimic the FromStr
implementation for the given types.
Links and related work
A PR implementing this is available here.