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