Skip to main content

Version

Struct Version 

Source
pub struct Version {
    pub kind: VersionKind,
    pub normalized: String,
}

Fields§

§kind: VersionKind§normalized: String

Canonical normalized form. Always equal to what Composer’s VersionParser::normalize returns for the same input.

Implementations§

Source§

impl Version

Source

pub fn parse(s: &str) -> Result<Self, ParseError>

Parse a Composer version string into its normalized form. Equivalent to PHP’s VersionParser::normalize($s).

§Panics

Doesn’t, despite the internal unwraps on caps.get(N): every group those reach is statically guaranteed to capture by the regex shape (\d{1,5} at position 1 etc.). The compile-time regex constructors also .unwrap() — those run once at first call and would only fire if the regex literal itself were ill-formed (caught at test time).

Source

pub fn parse_numeric_alias_prefix(branch: &str) -> Option<String>

Composer’s parseNumericAliasPrefix($branch). Given a branch name like 1.x-dev returns Some("1."); for non-aliases returns None.

Source

pub fn normalize_branch(branch: &str) -> String

Composer’s normalizeBranch($branch) — distinct from normalize in that the input is a branch name (no dev- prefix). Numeric-wildcard branches normalize to the same 9999999-padded form parse would produce; everything else becomes dev-<name>.

Source

pub fn parse_stability(version: &str) -> Stability

Composer’s parseStability($version). Mirrors the upstream algorithm directly: strip #commit, fast-path dev- prefix and -dev suffix, then run the modifier regex against the lower-cased input and read the keyword + dev capture from the match.

Source§

impl Version

Source

pub fn stability(&self) -> Stability

Composer’s Package::getStability() applied to a parsed Version. Branch versions are always Dev; numeric versions inherit their Suffix’s stability (Stable for bare, Patch(_); Dev for bare -dev; the prerelease keyword otherwise). This is the granular stability used to filter candidates against minimum-stability and per-package stability flags.

Source

pub fn compare(&self, op: CmpOp, other: &Version) -> bool

Composer’s comparator. Returns false for every op when the two operands are bare dev branches with different names; == is true only when both are bare branches with the same name. Numeric-vs-Branch comparisons use the standard Ord (Branch < Numeric).

Source

pub fn normalize_default_branch(normalized: &str) -> String

Composer’s normalizeDefaultBranch. Called by sort (NOT by normalize/parse) to massage dev-master, dev-default, dev-trunk into 9999999-dev so they sort above numeric versions. Other dev branches pass through unchanged.

Source

pub fn with_suffix(&self, suffix: Suffix) -> Option<Version>

Construct a Version with the same numeric body as self but the given suffix. Returns None for VersionKind::Branch (a branch ref has no numeric body to attach a suffix to).

Used by the Composer-to-pubgrub Ranges<Version> conversion to synthesize boundary markers: <X becomes strictly_lower_than(X.with_suffix(Suffix::Dev)) so that every prerelease of X (which sorts ≥ X-dev) is excluded.

Trait Implementations§

Source§

impl Clone for Version

Source§

fn clone(&self) -> Version

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Version

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Display for Version

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Eq for Version

Source§

impl Hash for Version

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl Ord for Version

Source§

fn cmp(&self, other: &Self) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 (const: unstable) · Source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 (const: unstable) · Source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 (const: unstable) · Source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized,

Restrict a value to a certain interval. Read more
Source§

impl PartialEq for Version

Source§

fn eq(&self, other: &Version) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl PartialOrd for Version

Source§

fn partial_cmp(&self, other: &Self) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 (const: unstable) · Source§

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 (const: unstable) · Source§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 (const: unstable) · Source§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 (const: unstable) · Source§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl StructuralPartialEq for Version

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.