#reserved #string #keyword


A trait for String-like types to check if it is a reserved keyword and convert it to a safe non-keyword if so

3 unstable releases

0.2.0 Dec 3, 2021
0.1.1 Jun 13, 2021
0.1.0 Jun 13, 2021

#689 in Rust patterns

Download history 365/week @ 2024-01-05 320/week @ 2024-01-12 547/week @ 2024-01-19 444/week @ 2024-01-26 526/week @ 2024-02-02 470/week @ 2024-02-09 544/week @ 2024-02-16 550/week @ 2024-02-23 348/week @ 2024-03-01 437/week @ 2024-03-08 520/week @ 2024-03-15 714/week @ 2024-03-22 692/week @ 2024-03-29 729/week @ 2024-04-05 861/week @ 2024-04-12 602/week @ 2024-04-19

2,985 downloads per month
Used in 22 crates (7 directly)


124 lines


A trait for String-like types to check if a string is a reserved keyword, and convert it to a safe non-keyword if so.

Only strict and reserved keywords are checked against; weak keywords are not included.

You can add this dependency with:

check_keyword = "0.2"


use check_keyword::CheckKeyword;
let keyword = "match";

assert_eq!(keyword.into_safe(), "r#match");

The CheckKeyword::into_safe method automatically checks CheckKeyword::is_keyword for you. You don't need to call CheckKeyword::is_keyword if you don't care whether it was originally a keyword or not.


There is a special implementation of CheckKeyword<String> for [&str], and a blanket implementation of CheckKeyword<T> where T: AsRef<str> + From<String>.

The blanket implementation covers [String], and is only tested for that, but should cover any other String-like type as well. I can try to broaden the definition to fit other types if needed (open an issue).

Rust Editions

By default, the keywords added in Rust Edition 2018 are included in the list of checked keywords. This can be disabled with default-features = false in your Cargo.toml.

check_keyword = { version = "0.2", default-features = false }

Future Rust editions may add new keywords, and this crate will be updated to reflect that. (Or you can create an issue on github if I don't.)

License: MIT OR Apache-2.0

No runtime deps