macro_rules! forward_from_str {
(<$($generic:ident),+> in $this:ty => $inner:ty $(,)?) => { ... };
(<$($generic:ident),+> in $this:ty => $field:ident : $inner:ty $(,)?) => { ... };
($this:ty => $inner:ty $(,)?) => { ... };
($this:ty => $field:ident : $inner:ty $(,)?) => { ... };
}Expand description
Implement FromStr by forwarding to a field’s implementation.
The first argument is the struct to create the impl for and the second is the field type whose
FromStr implementation is used.
§Examples
With a newtype struct:
use impl_more::forward_from_str;
#[derive(Debug, PartialEq)]
struct Port(u16);
forward_from_str!(Port => u16);
assert_eq!("8080".parse(), Ok(Port(8080)));With a named field struct and type parameters:
use impl_more::forward_from_str;
#[derive(Debug, PartialEq)]
struct Value<T> { inner: T }
forward_from_str!(<T> in Value<T> => inner: T);
assert_eq!("true".parse(), Ok(Value { inner: true }));