macro_rules! impl_from { (<$($generic:ident),+> in $from:ty => $this:ty $(,)?) => { ... }; (<$($generic:ident),+> in $from:ty => $this:ty : $field:ident $(,)?) => { ... }; ($from:ty => $this:ty $(,)?) => { ... }; ($from:ty => $this:ty : $field:ident $(,)?) => { ... }; }
Expand description
Implement From
for a struct.
Examples
With a newtype struct:
use impl_more::impl_from;
struct Foo(String);
impl_from!(String => Foo);
let foo = Foo::from("bar".to_owned());
With a named field struct with type parameters:
use std::rc::Rc;
use impl_more::impl_from;
struct Foo<T> { inner: Rc<T> }
impl_from!(<T> in Rc<T> => Foo<T> : inner);
let foo = Foo::from(Rc::new("bar".to_owned()));