newtype_wrap

Macro newtype_wrap 

Source
macro_rules! newtype_wrap {
    ($wrapper: ident, $wrapped: ty) => { ... };
    ($wrapper: ty, $variant: ident, $wrapped: ty) => { ... };
}
Expand description

Implement conversion from T to its newtype wrapper.

Also works on types that convert to T via into().

The wrapper can either be a newtype struct or a newtype variant of an enum:

  • Struct
    • Given struct Foo(T); and impl From<U> for T
    • newtype_wrap!(Foo, T); implements T -> Foo(T)
    • newtype_wrap!(Foo, U); implements U -> Foo(T)
  • Enum
    • Given enum Foo{ Bar(T) }; and impl From<U> for T
    • newtype_wrap!(Foo, Bar, T); implements T -> Foo::Bar(T)
    • newtype_wrap!(Foo, Bar, U); implements U -> Foo::Bar(T)