| Crates.io | match_to_str |
| lib.rs | match_to_str |
| version | 0.1.0 |
| created_at | 2023-09-10 02:13:02.953944+00 |
| updated_at | 2023-09-10 02:13:02.953944+00 |
| description | match pattern to str |
| homepage | |
| repository | https://github.com/kumavale/match_to_str |
| max_upload_size | |
| id | 968492 |
| size | 19,803 |
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.
$ 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",
_ => "_",
};
This project welcomes your PR and issues. For example, fixing bugs, adding features, refactoring, etc.