Derive Macro fundamental_data_type::From
source · #[derive(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.