extendr_api::scalar::macros

Macro gen_binopassign

Source
macro_rules! gen_binopassign {
    ($type : ty, $type_prim : ty, $opname : ident, $expr: expr, $docstring: expr) => { ... };
}
Expand description

Generates an implementation of a binary operate-assign Trait for a scalar type

This macro requires the following arguments:

  • $type - The Type the binary operate-assign Trait is implemented for
  • $type_prim - The primitive Rust scalar type that corresponds to $type
  • $opname - The Trait for which the implementation is generated
  • $expr - A closure providing the logic for the implementation
  • $docstring - String to include as the Doc comment for the Trait implementation

Example Usage:

gen_binopassign!(Rint, i32, AddAssign, |lhs: i32, rhs| lhs.checked_add(rhs), "Doc Comment");

The ‘example usage’ implements the following trait definitions:

  • impl AddAssign<Rint> for Rint
  • impl AddAssign<Rint> for &mut Rint
  • impl AddAssign<i32> for Rint
  • impl AddAssign<i32> for &mut Rint
  • impl AddAssign<Rint> for Option<i32>