[][src]Macro is::is

macro_rules! is {
    ($($(#[$docs:meta])* impl $function:ident for 'static $T:ty);+ $(;)*) => { ... };
}

This macro is the main entry point of this crate

Examples

Creation of 'static type checking functions

Syntax:

is! {
    /// Documentation for fn is_t(&'static value) -> bool
    /// Checks if value is of type T
    impl is_t for 'static T;

    // ...

    /// Documentation for fn is_e(&'static value) -> bool
    /// Checks if value is of type E
    impl is_e for 'static E; // this ';' is optional
}

Simple usage:

// creates function that checks if given value is of type i32
is! { impl is_i32 for 'static i32 }

assert_eq!(is_i32(&42i32), true);
assert_eq!(is_i32(&42u32), false);

// This macro can be used to implement type checking for any type
// Generics are implementation defined
is! {
    impl is_vec_u8 for 'static Vec<u8>;
    impl is_vec_u16 for 'static Vec<u16>;
}

let vecu8: Vec<u8> = vec![42; 3];
let vecu16: Vec<u16> = vec![42; 3];

assert_eq!(is_vec_u8(&vecu8), true);
assert_eq!(is_vec_u8(&vecu16), false);

assert_eq!(is_vec_u16(&vecu16), true);
assert_eq!(is_vec_u16(&vecu8), false);