match_to_str

Crates.iomatch_to_str
lib.rsmatch_to_str
version0.1.0
created_at2023-09-10 02:13:02.953944+00
updated_at2023-09-10 02:13:02.953944+00
descriptionmatch pattern to str
homepage
repositoryhttps://github.com/kumavale/match_to_str
max_upload_size
id968492
size19,803
Naoki Kumagai (kumavale)

documentation

README

match_to_str

Actions Status Crate license license

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.

Usage

$ cargo add match_to_str
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");
}

expand to:

let animal = match 1 {
    CAT => "CAT",
    DOG => "DOG",
    _ => "_",
};

Contributing

This project welcomes your PR and issues. For example, fixing bugs, adding features, refactoring, etc.

Commit count: 10

cargo fmt