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 may skip AsMut and BorrowMut implementations with #[wrapper_mut(NoRefs)].

You can implement additional derives, it they are implemented for the wrapped type, using #[wrapper()] proc macro:

  1. Reference access to the inner type:
    • DerefMut for implementing [core::ops::DerefMut]
    • AsSliceMut for implementing [AsMut]<[u8]>
    • BorrowSliceMut for implementing [core::borrow::BorrowMut]<[Self::Inner]>
  2. Indexed access to the inner type:
    • IndexMut for implementing [core::ops::IndexMut]<usize>
    • IndexRangeMut for implementing [core::ops::IndexMut]<[core::ops::Range]<usize>>
    • IndexToMut for implementing [core::ops::IndexMut]<[core::ops::RangeTo]<usize>>
    • IndexFromMut for implementing [core::ops::IndexMut]<[core::ops::RangeFrom]<usize>>
    • IndexInclusiveMut for implementing [core::ops::IndexMut]<[core::ops::RangeInclusive]<usize>>
    • IndexToInclusiveMut for implementing [core::ops::IndexMut]<[core::ops::RangeToInclusive]<usize>>
    • IndexFullMut for implementing [core::ops::IndexMut]<[core::ops::RangeFrom]<usize>>
  3. Arithmetic operations:
    • AddAssign for implementing [core::ops::AddAssign]
    • SubAssign for implementing [core::ops::SubAssign]
    • MulAssign for implementing [core::ops::MulAssign]
    • DivAssign for implementing [core::ops::DivAssign]
    • RemAssign for implementing [core::ops::RemAssign]
  4. Boolean and bit-wise operations:
    • BitAndAssign for implementing [core::ops::BitAndAssign]
    • BitOrAssign for implementing [core::ops::BitOrAssign]
    • BitXorAssign for implementing [core::ops::BitXorAssign]
    • ShlAssign for implementing [core::ops::ShlAssign]
    • ShrAssign for implementing [core::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, FromStr)]
#[wrapper_mut(MathAssign, BitAssign)]
struct Int64(i64);