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);andimpl From<U> for T newtype_wrap!(Foo, T);implementsT -> Foo(T)newtype_wrap!(Foo, U);implementsU -> Foo(T)
- Given
- Enum
- Given
enum Foo{ Bar(T) };andimpl From<U> for T newtype_wrap!(Foo, Bar, T);implementsT -> Foo::Bar(T)newtype_wrap!(Foo, Bar, U);implementsU -> Foo::Bar(T)
- Given