pub struct Version {
pub kind: VersionKind,
pub normalized: String,
}Fields§
§kind: VersionKind§normalized: StringCanonical normalized form. Always equal to what Composer’s
VersionParser::normalize returns for the same input.
Implementations§
Source§impl Version
impl Version
Sourcepub fn parse(s: &str) -> Result<Self, ParseError>
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).
Sourcepub fn parse_numeric_alias_prefix(branch: &str) -> Option<String>
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.
Sourcepub fn normalize_branch(branch: &str) -> String
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>.
Sourcepub fn parse_stability(version: &str) -> Stability
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
impl Version
Sourcepub fn stability(&self) -> Stability
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.
Sourcepub fn compare(&self, op: CmpOp, other: &Version) -> bool
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).
Sourcepub fn normalize_default_branch(normalized: &str) -> String
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.
Sourcepub fn with_suffix(&self, suffix: Suffix) -> Option<Version>
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.