Macro auto_ops::impl_op_ex [−][src]
Overloads an operator using the given closure as its body. Generates overloads for both owned and borrowed variants where possible.
Used with the same syntax as impl_op!
(see the module level documentation for more information).
Expands any borrowed inputs into both owned and borrowed variants.
impl_op_ex!(op |a: &LHS, b: &RHS| -> OUT {...});
gets expanded to
ⓘ
impl_op!(op |a: LHS, b: RHS| -> OUT {...}); impl_op!(op |a: LHS, b: &RHS| -> OUT {...}); impl_op!(op |a: &LHS, b: RHS| -> OUT {...}); impl_op!(op |a: &LHS, b: &RHS| -> OUT {...});
and impl_op_ex!(op |a: &LHS, b: RHS| -> OUT {...});
gets expanded to
ⓘ
impl_op!(op |a: LHS, b: RHS| -> OUT {...}); impl_op!(op |a: &LHS, b: RHS| -> OUT {...});
Examples
use auto_ops::impl_op_ex; impl_op_ex!(+ |a: &DonkeyKong, b: &DonkeyKong| -> i32 { a.bananas + b.bananas }); fn main() { let total_bananas = &DonkeyKong::new(2) + &DonkeyKong::new(4); assert_eq!(6, total_bananas); let total_bananas = &DonkeyKong::new(2) + DonkeyKong::new(4); assert_eq!(6, total_bananas); let total_bananas = DonkeyKong::new(2) + &DonkeyKong::new(4); assert_eq!(6, total_bananas); let total_bananas = DonkeyKong::new(2) + DonkeyKong::new(4); assert_eq!(6, total_bananas); }