extendr_api::scalar::macros

Macro gen_binop

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

Generates an implementation of a binary operator Trait for a scalar type

This macro requires the following arguments:

  • $type - The Type the binary operator 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_binop!(Rint, i32, Add, |lhs: i32, rhs| lhs.checked_add(rhs), "Doc Comment");

The ‘example usage’ implements the following trait definitions:

  • impl Add<Rint> for Rint
  • impl Add<Rint> for &Rint
  • impl Add<i32> for Rint
  • impl Add<Rint> for i32