Macro twitch_api_rs::ident [−][src]
Create identity functions for Eq types
generates two functions
ⓘ
fn ident_to(a: &A) -> Option<&'static B> { /* ... */ } fn ident_from(b: &B) -> Option<&'static A> { /* ... */ }
Examples
struct Scopes(); impl Scopes { ident!(pub <usize, str>: [ 00 => "read", 01 => "write", 02 => "execute" ]); } // Go from A to B assert_eq!( Scopes::ident_to(&0), Some("read") ); // Go from B to A assert_eq!( Scopes::ident_from("write"), Some(&1) ); // Do nothing for undefined values assert_eq!( Scopes::ident_to(&45), None );