Derive Macro amplify::WrapperMut
source · #[derive(WrapperMut)]
{
// Attributes available to this derive:
#[wrap]
#[wrapper_mut]
#[amplify_crate]
}
Expand description
Derives WrapperMut
and allows deriving other traits accessing the
wrapped type which require mutable access to the inner type. Requires that
the type already implements amplify::Wrapper
.
Supports automatic implementation of the following traits:
amplify::WrapperMut
AsMut
core::borrow::BorrowMut
You can implement additional derives, it they are implemented for the wrapped
type, using #[wrapper()]
proc macro:
- Reference access to the inner type:
DerefMut
for implementingcore::ops::DerefMut
BorrowSliceMut
for implementingcore::borrow::BorrowMut
<[Self::Inner]>
- Indexed access to the inner type:
IndexMut
for implementingcore::ops::IndexMut
<usize>
IndexRangeMut
for implementingcore::ops::IndexMut
<
core::ops::Range
<usize>>
IndexToMut
for implementingcore::ops::IndexMut
<
core::ops::RangeTo
<usize>>
IndexFromMut
for implementingcore::ops::IndexMut
<
core::ops::RangeFrom
<usize>>
IndexInclusiveMut
for implementingcore::ops::IndexMut
<
core::ops::RangeInclusive
<usize>>
IndexToInclusiveMut
for implementingcore::ops::IndexMut
<
core::ops::RangeToInclusive
<usize>>
IndexFullMut
for implementingcore::ops::IndexMut
<
core::ops::RangeFrom
<usize>>
- Arithmetic operations:
AddAssign
for implementingcore::ops::AddAssign
SubAssign
for implementingcore::ops::SubAssign
MulAssign
for implementingcore::ops::MulAssign
DivAssign
for implementingcore::ops::DivAssign
RemAssign
for implementingcore::ops::RemAssign
- Boolean and bit-wise operations:
BitAndAssign
for implementingcore::ops::BitAndAssign
BitOrAssign
for implementingcore::ops::BitOrAssign
BitXorAssign
for implementingcore::ops::BitXorAssign
ShlAssign
for implementingcore::ops::ShlAssign
ShrAssign
for implementingcore::ops::ShrAssign
There are shortcuts for derivations:
#[wrapper(RangeMut)]
will derive all index traits working with ranges (IndexRangeMut
,IndexToMut
,IndexFromMut
,IndexInclusiveMut
,IndexToInclusiveMut
,IndexFullMut
);#[wrapper(MathAssign)]
will derive all arithmetic operations (AddAssign
,SubAssign
,MulAssign
,DivAssign
,RemAssign
);#[wrapper(BoolAssign)]
will derive all boolean operations (BitAndAssign
,BitOrAssign
,BitXorAssign
);#[wrapper(BitAssign)]
will derive all boolean operations and bit shifts (BitAndAssign
,BitOrAssign
,BitXorAssign
,ShlAssign
,ShrAssign
);
Example
use amplify::{Wrapper, WrapperMut};
#[derive(
Wrapper, WrapperMut, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Default, From, Debug,
Display,
)]
#[display(inner)]
#[wrapper(NumberFmt, MathOps, BoolOps)]
#[wrapper_mut(MathAssign, BitAssign)]
struct Int64(i64);