#[derive(New)]
{
// Attributes available to this derive:
#[debug]
#[new]
}
Expand description
Provides an automatic new 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 new for IsTransparent:
pub struct IsTransparent( bool );
impl IsTransparent
{
#[ inline( always ) ]
fn new( src : bool ) -> Self
{
Self( src )
}
}Use #[ derive( New ) ] to automatically generate the implementation:
#[ derive( New ) ]
pub struct IsTransparent( bool );The macro facilitates the conversion without additional boilerplate code.