#[derive(IndexMut)]
{
// Attributes available to this derive:
#[debug]
#[index]
}
Expand description
Reusing main crate.
Provides an automatic IndexMut trait implementation when-ever it’s possible.
This macro simplifies the indexing syntax of struct type.
§Example Usage
Instead of manually implementing IndexMut< T >
for IsTransparent
:
use core::ops::{ Index, IndexMut };
pub struct IsTransparent< T >
{
a : Vec< T >,
}
impl< T > Index< usize > for IsTransparent< T >
{
type Output = T;
#[ inline( always ) ]
fn index( &self, index : usize ) -> &Self::Output
{
&self.a[ index ]
}
}
impl< T > IndexMut< usize > for IsTransparent< T >
{
fn index_mut( &mut self, index : usize ) -> &mut Self::Output
{
&mut self.a[ index ]
}
}
Use #[ index ]
on field or #[ index( name = field_name )]
on named items to automatically generate the implementation:
use derive_tools_meta::*;
#[derive( IndexMut )]
pub struct IsTransparent< T >
{
#[ index ]
a : Vec< T >
};