Module rust_keywords
Expand description
Rust keyword classification, shared by cratestack-parser (schema-time
field-name validation) and cratestack-macros (identifier escaping at
codegen time) so the two stay in sync — see cratestack#398.
A .cstack field name is an arbitrary wire-format string; codegen turns
it into a Rust identifier verbatim. If that string happens to be a Rust
keyword, the naive identifier is not valid Rust. Most keywords have a
raw-identifier escape hatch (r#type, r#match, …); four do not
(self, Self, super, crate — rustc rejects r#self outright) and
must be rejected before codegen ever sees them.
Constants§
- UNREPRESENTABLE_
KEYWORDS - Keywords that cannot be represented as a Rust identifier at all, not even
as a raw identifier. Per the Rust reference,
r#self,r#Self,r#super, andr#crateare explicitly disallowed by the compiler — there is no valid spelling, so a field with one of these names must be rejected at schema-parse time rather than escaped.
Functions§
- is_
raw_ escapable_ keyword trueifnameis a Rust keyword that can be emitted asr#name.- is_
rust_ keyword trueifnameis a Rust keyword that needs handling before it can be emitted as a Rust identifier — either raw-identifier escaping (seeis_raw_escapable_keyword) or outright rejection (seeis_unrepresentable_keyword).- is_
unrepresentable_ keyword trueifnameis a Rust keyword with no valid identifier spelling at all —self,Self,super,crate.