pub struct PythonVersion { /* private fields */ }Expand description
Lightweight Python version metadata.
Implementations§
Source§impl PythonVersion
impl PythonVersion
Sourcepub fn new(
major: u16,
minor: Option<u16>,
patch: Option<u16>,
) -> Result<PythonVersion, PythonVersionParseError>
pub fn new( major: u16, minor: Option<u16>, patch: Option<u16>, ) -> Result<PythonVersion, PythonVersionParseError>
Creates Python version metadata.
§Errors
Returns PythonVersionParseError::InvalidVersion when the major version is zero or
a patch component is present without a minor component.
Sourcepub const fn is_python3(&self) -> bool
pub const fn is_python3(&self) -> bool
Returns whether this version is in the Python 3 family.
Examples found in repository?
examples/basic_usage.rs (line 12)
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 is_prerelease_like(&self) -> bool
pub fn is_prerelease_like(&self) -> bool
Returns whether the parsed suffix looks like a prerelease marker.
Trait Implementations§
Source§impl Clone for PythonVersion
impl Clone for PythonVersion
Source§fn clone(&self) -> PythonVersion
fn clone(&self) -> PythonVersion
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 PythonVersion
impl Debug for PythonVersion
Source§impl Display for PythonVersion
impl Display for PythonVersion
Source§impl FromStr for PythonVersion
impl FromStr for PythonVersion
Source§type Err = PythonVersionParseError
type Err = PythonVersionParseError
The associated error which can be returned from parsing.
Source§fn from_str(
input: &str,
) -> Result<PythonVersion, <PythonVersion as FromStr>::Err>
fn from_str( input: &str, ) -> Result<PythonVersion, <PythonVersion as FromStr>::Err>
Parses a string
s to return a value of this type. Read moreSource§impl Hash for PythonVersion
impl Hash for PythonVersion
Source§impl Ord for PythonVersion
impl Ord for PythonVersion
Source§fn cmp(&self, other: &PythonVersion) -> Ordering
fn cmp(&self, other: &PythonVersion) -> 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 PythonVersion
impl PartialEq for PythonVersion
Source§fn eq(&self, other: &PythonVersion) -> bool
fn eq(&self, other: &PythonVersion) -> bool
Tests for
self and other values to be equal, and is used by ==.Source§impl PartialOrd for PythonVersion
impl PartialOrd for PythonVersion
impl Eq for PythonVersion
impl StructuralPartialEq for PythonVersion
Auto Trait Implementations§
impl Freeze for PythonVersion
impl RefUnwindSafe for PythonVersion
impl Send for PythonVersion
impl Sync for PythonVersion
impl Unpin for PythonVersion
impl UnsafeUnpin for PythonVersion
impl UnwindSafe for PythonVersion
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