Skip to main content

Crate use_python_identifier

Crate use_python_identifier 

Source
Expand description

§use-python-identifier

ASCII-safe Python identifier primitives for RustUse.

§Experimental

use-python-identifier is experimental while use-python remains below 0.3.0.

§Example

use use_python_identifier::{PythonIdentifier, is_valid_ascii_python_identifier};

let identifier = PythonIdentifier::new("async_task")?;

assert_eq!(identifier.as_str(), "async_task");
assert!(is_valid_ascii_python_identifier("_value_1"));

§Scope

  • Ordinary ASCII-safe Python identifier validation.
  • Hard Python keyword rejection through use-python-keyword.
  • Dunder-name and private-name metadata helpers.

§Non-goals

  • Complete Unicode Python identifier validation.
  • Soft-keyword context analysis.
  • Python source-code parsing.

Unicode-complete Python identifier validation is future work.

§License

Licensed under either Apache-2.0 or MIT.

Structs§

PythonDunderName
Validated Python dunder name metadata.
PythonIdentifier
Validated ASCII-safe Python identifier.
PythonPrivateName
Validated Python private-name metadata.

Enums§

PythonIdentifierError
Error returned when an ASCII Python identifier is invalid.

Functions§

is_ascii_python_identifier_continue
Returns whether character is accepted after the first identifier character.
is_ascii_python_identifier_start
Returns whether character is accepted as an ASCII Python identifier start.
is_dunder_name
Returns whether input looks like a Python dunder name such as __init__.
is_private_name
Returns whether input looks like a single-underscore private name.
is_valid_ascii_python_identifier
Returns whether input is an ASCII-safe Python identifier and not a hard keyword.