Type Definition parsel::ast::Word

source · []
pub type Word = CustomIdent<AllowAll>;
Expand description

Convenience type alias for an identifier that successfully parses from any single word, including Rust keywords. (This is in contrast with the default behavior of Ident.)

let non_kw: Word = parse_quote!(not_a_keyword);
assert_eq!(non_kw, "not_a_keyword");

let underscore: Word = parse_quote!(_);
assert_eq!(underscore, "_");

let keyword_fn: Word = parse_quote!(fn);
assert_eq!(keyword_fn, "fn");

let keyword_pub: Word = parse_quote!(pub);
assert_eq!(keyword_pub, "pub");

Implementations

This is only defined on Word and not on CustomIdent in general, because this practice prevents users from accidentally creating an invalid identifier (one that is a keyword, as defined by the user).