Macro extendr_api::scalar::macros::gen_unop

source ·
macro_rules! gen_unop {
    ($type : ty, $opname : ident, $expr: expr, $docstring: expr) => { ... };
}
Expand description

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

Generates the implementation of the specified unary operator for both Type and &Type, using the logic of the provided closure to provide functionality.

This macro requires the following arguments:

  • $type - The Type the unary operator Trait is implemented for
  • $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_unop!(Rint, Neg, |lhs: i32| Some(-lhs), "Doc Comment");

The ‘example usage’ implements the following trait definitions:

  • impl Neg for Rint
  • impl Neg for &Rint