Crate match_to_str

Crate match_to_str 

Source
Expand description

§match_to_str

Converts the pattern part of the match expression into a &'static str.
It is mainly intended to be used when you want to convert a variable name into a string as is.

use match_to_str::match_to_str;

const CAT: u8 = 1;
const DOG: u8 = 2;

fn main() {
    let animal = match_to_str!(1 => {
        CAT,
        DOG,
        _,
    });
    assert_eq!(animal, "CAT");
}

Macros§

match_to_str
Converts the pattern part of the match expression into a &'static str.