extendr_api::scalar::macros

Macro gen_trait_impl

Source
macro_rules! gen_trait_impl {
    ($type : ident, $type_prim : ty, $na_check : expr, $na_val : expr) => { ... };
}
Expand description

Generates an implementation of a number of Traits for the specified Type

This macro requires the following arguments:

  • $type - The Type the Traits are implemented for
  • $type_prim - The primitive Rust scalar type that corresponds to $type
  • $na_check - Closure that provides NA-checking logic
  • $na_val - The Rust-native value that translates to NA

Example Usage:

gen_trait_impl!(Rint, i32, |x: &Rint| x.0 == i32::MIN, i32::MIN);

The ‘example usage’ implements the following trait definitions:

  • impl Clone for Rint
  • impl Copy for Rint
  • impl CanBeNA for Rint // Includes doc test
  • impl Debug for Rint
  • impl PartialEq<Rint> for Rint // Includes doc test
  • impl PartialEq<i32> for Rint // Includes doc test
  • impl Default for Rint // Includes doc test