Skip to main content

rust_raw_ident_safe

Function rust_raw_ident_safe 

Source
pub fn rust_raw_ident_safe(name: &str) -> Option<String>
Expand description

Escape a name that is a Rust keyword by prepending the raw-identifier prefix (r#).

Returns Some("r#<name>") when name is a Rust keyword, None otherwise. Use this when emitting a Rust identifier (function parameter, struct-literal field, local variable) whose text comes from an external source (e.g. a serde rename) and may coincide with a reserved word.

Note: PyO3 strips the r# prefix when deriving the Python-facing name, so a parameter declared as r#type is still exposed to Python as type.