Macro ShlAssign
macro_rules! ShlAssign { ... }
What #[derive(MulAssign)] generates
NOTE:
DivAssign,RemAssign,ShrAssignandShlAssignderives are fully equivalent to theMulAssignderive described below.
Deriving MulAssign is very similar to deriving Mul. The difference is that it
mutates the existing instance instead of creating a new one.
Scalar implementation
Structs
Deriving MulAssign for a struct with multiple fields multiplies its fields with
anything multiplicable, mutating them in-place.
# use MulAssign;
#
;
This generates code equivalent to:
# use MulAssign;
#
# ;
#
#
#
Note, that Copyis not required for Rhs when the struct has only a single field.
Ignoring
Sometimes a struct needs to hold a field (most commonly PhantomData) that doesn't
participate in a scalar MulAssign implementation. Such field could be ignored using
the #[mul_assign(skip)] attribute.
# use PhantomData;
# use MulAssign;
#
] );
Enums
Deriving scalar MulAssign implementation for enums is not (yet) supported (in the same manner as deriving Mul).
Although it shouldn't be impossible no effort has been put into this yet.
Structural implementation
Specifying the #[mul_assign(forward)] attribute generates a structural MulAssign
implementation with the same semantics as AddAssign: MulAssigning the respective
fields, mutating them in-place.
Structs
# use MulAssign;
#
;
This generates code equivalent to:
# use MulAssign;
#
# ;
#
#
#
The behaviour is similar with more or less fields.
Ignoring
Sometimes a struct needs to hold a field (most commonly PhantomData) that doesn't
participate in a structural MulAssign implementation. Such field could be ignored using
the #[mul_assign(skip)] attribute.
# use PhantomData;
# use MulAssign;
#
] );
Enums
Deriving AddAssign structurally is not (yet) supported for enums.
This is mostly due to the fact that it is not trivial convert the Mul
derivation code, because that returns a Result<EnumType> instead of an EnumType.
Handling the case where it errors would be hard and maybe impossible.