pub struct PythonIdentifier(/* private fields */);Expand description
Validated ASCII-safe Python identifier.
Implementations§
Source§impl PythonIdentifier
impl PythonIdentifier
Sourcepub fn new(input: &str) -> Result<PythonIdentifier, PythonIdentifierError>
pub fn new(input: &str) -> Result<PythonIdentifier, PythonIdentifierError>
Creates an ASCII-safe Python identifier that is not a hard Python keyword.
§Errors
Returns PythonIdentifierError when input is empty, keyword-shaped, or not ASCII identifier-shaped.
Examples found in repository?
examples/basic_usage.rs (line 8)
6fn main() -> Result<(), Box<dyn std::error::Error>> {
7 let version: PythonVersion = "Python 3.12.1".parse()?;
8 let identifier = PythonIdentifier::new("async_task")?;
9 let requirement = PipRequirement::new("requests>=2")?;
10 let node_id = PytestNodeId::new("tests/test_app.py::test_smoke")?;
11
12 assert!(version.is_python3());
13 assert_eq!(identifier.as_str(), "async_task");
14 assert_eq!(PythonImplementation::CPython.as_str(), "cpython");
15 assert_eq!(PythonPrimitiveValue::None.type_name(), "NoneType");
16 assert!(!requirement.is_editable());
17 assert!(node_id.has_scope_separator());
18 Ok(())
19}Sourcepub fn as_str(&self) -> &str
pub fn as_str(&self) -> &str
Returns the identifier as a string slice.
Examples found in repository?
examples/basic_usage.rs (line 13)
6fn main() -> Result<(), Box<dyn std::error::Error>> {
7 let version: PythonVersion = "Python 3.12.1".parse()?;
8 let identifier = PythonIdentifier::new("async_task")?;
9 let requirement = PipRequirement::new("requests>=2")?;
10 let node_id = PytestNodeId::new("tests/test_app.py::test_smoke")?;
11
12 assert!(version.is_python3());
13 assert_eq!(identifier.as_str(), "async_task");
14 assert_eq!(PythonImplementation::CPython.as_str(), "cpython");
15 assert_eq!(PythonPrimitiveValue::None.type_name(), "NoneType");
16 assert!(!requirement.is_editable());
17 assert!(node_id.has_scope_separator());
18 Ok(())
19}Trait Implementations§
Source§impl Clone for PythonIdentifier
impl Clone for PythonIdentifier
Source§fn clone(&self) -> PythonIdentifier
fn clone(&self) -> PythonIdentifier
Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for PythonIdentifier
impl Debug for PythonIdentifier
Source§impl Display for PythonIdentifier
impl Display for PythonIdentifier
Source§impl FromStr for PythonIdentifier
impl FromStr for PythonIdentifier
Source§type Err = PythonIdentifierError
type Err = PythonIdentifierError
The associated error which can be returned from parsing.
Source§fn from_str(
input: &str,
) -> Result<PythonIdentifier, <PythonIdentifier as FromStr>::Err>
fn from_str( input: &str, ) -> Result<PythonIdentifier, <PythonIdentifier as FromStr>::Err>
Parses a string
s to return a value of this type. Read moreSource§impl Hash for PythonIdentifier
impl Hash for PythonIdentifier
Source§impl Ord for PythonIdentifier
impl Ord for PythonIdentifier
Source§fn cmp(&self, other: &PythonIdentifier) -> Ordering
fn cmp(&self, other: &PythonIdentifier) -> Ordering
1.21.0 (const: unstable) · Source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
Compares and returns the maximum of two values. Read more
Source§impl PartialEq for PythonIdentifier
impl PartialEq for PythonIdentifier
Source§fn eq(&self, other: &PythonIdentifier) -> bool
fn eq(&self, other: &PythonIdentifier) -> bool
Tests for
self and other values to be equal, and is used by ==.Source§impl PartialOrd for PythonIdentifier
impl PartialOrd for PythonIdentifier
Source§impl TryFrom<&str> for PythonIdentifier
impl TryFrom<&str> for PythonIdentifier
Source§type Error = PythonIdentifierError
type Error = PythonIdentifierError
The type returned in the event of a conversion error.
Source§fn try_from(
value: &str,
) -> Result<PythonIdentifier, <PythonIdentifier as TryFrom<&str>>::Error>
fn try_from( value: &str, ) -> Result<PythonIdentifier, <PythonIdentifier as TryFrom<&str>>::Error>
Performs the conversion.
impl Eq for PythonIdentifier
impl StructuralPartialEq for PythonIdentifier
Auto Trait Implementations§
impl Freeze for PythonIdentifier
impl RefUnwindSafe for PythonIdentifier
impl Send for PythonIdentifier
impl Sync for PythonIdentifier
impl Unpin for PythonIdentifier
impl UnsafeUnpin for PythonIdentifier
impl UnwindSafe for PythonIdentifier
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more