Derive Macro AsRef

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

Derive macro to implement AsRef when-ever it’s possible to do automatically.

§Sample :: struct instead of macro.

Write this

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

Instead of this

pub struct IsTransparent( bool );
impl AsRef< bool > for IsTransparent
{
  fn as_ref( &self ) -> &bool
  {
    &self.0
  }
}