Derive Macro From

Source
#[derive(From)]
{
    // Attributes available to this derive:
    #[debug]
    #[from]
}
Expand description

Provides an automatic From implementation for struct wrapping a single value.

This macro simplifies the conversion of an inner type to an outer struct type when the outer type is a simple wrapper around the inner type.

ยงExample Usage

Instead of manually implementing From< bool > for IsTransparent:

pub struct IsTransparent( bool );

impl From< bool > for IsTransparent
{
  #[ inline( always ) ]
  fn from( src : bool ) -> Self
  {
    Self( src )
  }
}

Use #[ derive( From ) ] to automatically generate the implementation:

#[ derive( From ) ]
pub struct IsTransparent( bool );

The macro facilitates the conversion without additional boilerplate code.