macro_rules! impl_from {
(<$($generic:ident),+> in $($rest:tt)+) => { ... };
(<const $($rest:tt)+) => { ... };
(<$generic:ident, $($rest:tt)+) => { ... };
(@impl [$($generic:tt)+] $from:ty => $this:ty $(,)?) => { ... };
(@impl [$($generic:tt)+] $from:ty => $this:ty : $field:ident $(,)?) => { ... };
($from:ty => $this:ty $(,)?) => { ... };
($from:ty => $this:ty : $field:ident $(,)?) => { ... };
}Expand description
Implement From for a struct.
Declare type and const parameters before in.
ยง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()));With type and const parameters:
struct Array<T, const N: usize>([T; N]);
impl_more::impl_from!(<T, const N: usize> in [T; N] => Array<T, N>);
let value = Array::from([1, 2, 3]);
assert_eq!(value.0, [1, 2, 3]);