Skip to main content

Module rust_keywords

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, and r#crate are 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
true if name is a Rust keyword that can be emitted as r#name.
is_rust_keyword
true if name is a Rust keyword that needs handling before it can be emitted as a Rust identifier — either raw-identifier escaping (see is_raw_escapable_keyword) or outright rejection (see is_unrepresentable_keyword).
is_unrepresentable_keyword
true if name is a Rust keyword with no valid identifier spelling at all — self, Self, super, crate.