Macro identical

Source
identical!() { /* proc-macro */ }
Expand description

Simple macro that checks if two supplied values are identical. If this is the case it will insert the specified expression. Otherwise it inserts nothing.

The macro can be used to omit code when two idents are not identical. It can also be used to check if an identifier is contained in a range of identifiers.

// Identifiers are not matching. This means that
// the last statement will never be inserted
identical!(MyFirstIdentifier, MySecondIdentifier, assert!(false));

// Identifiers are matching. The last statement
// (in this case `assert!(true)`) will be inserted into the code.
identical!(SameIdent, SameIdent, assert!(true));

// The String "hamster" is inserted here since both identifiers are matching.
assert_eq!("hamster", identical!(Id1, Id1, "hamster"));

// Identifiers are not equal if their capitalization does not match
identical!(caps, Caps, assert!(false));

// This works since 1_f64 is turned into a string and then
// compared to "1_f64" which is identically the same.
identical!(1_f64, "1_f64", assert!(true));

The macro is not going to compile if given only two idents

identical!(Id1, Id2);

The same holds true if we do not supply two identifiers.

identical!(Id1, println!("asdf"));