is_macro

Derive Macro Is

Source
#[derive(Is)]
{
    // Attributes available to this derive:
    #[is]
}
Expand description

A proc macro to generate methods like is_variant / expect_variant.

§Example

 
use is_macro::Is;
#[derive(Debug, Is)]
pub enum Enum<T> {
    A,
    B(T),
    C(Option<T>),
}

// Rust's type inference cannot handle this.
assert!(Enum::<()>::A.is_a());

assert_eq!(Enum::B(String::from("foo")).b(), Some(String::from("foo")));

assert_eq!(Enum::B(String::from("foo")).expect_b(), String::from("foo"));

§Renaming

 
use is_macro::Is;
#[derive(Debug, Is)]
pub enum Enum {
    #[is(name = "video_mp4")]
    VideoMp4,
}

assert!(Enum::VideoMp4.is_video_mp4());