Skip to main content

impl_into

Macro impl_into 

Source
macro_rules! impl_into {
    (<$($generic:ident),+> in $($rest:tt)+) => { ... };
    (<const $($rest:tt)+) => { ... };
    (<$generic:ident, $($rest:tt)+) => { ... };
    (@impl [$($generic:tt)+] $this:ty => $inner:ty : $field:ident) => { ... };
    (@impl [$($generic:tt)+] $this:ty => $inner:ty) => { ... };
    ($this:ty => $inner:ty) => { ... };
    ($this:ty => $inner:ty : $field:ident) => { ... };
}
Expand description

Implement Into for a struct.

Declare type and const parameters before in.

ยง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();