pub enum Constraint {
Any,
Op {
op: CmpOp,
version: Version,
explicit_lower_bound: bool,
},
And(Vec<Constraint>),
Or(Vec<Constraint>),
}Variants§
Any
* / x — matches everything.
Op
op X.Y.Z — atomic operator clause. explicit_lower_bound is
true when this clause is a >=/> whose version was written
in full (^1.2.3, >=1.2.3) rather than synthesized from a
partial expansion (1 → >=1.0.0). Composer admits same-numeric
prereleases at the lower bound only in the explicit case.
And(Vec<Constraint>)
Whitespace-or-comma-joined intersection.
Or(Vec<Constraint>)
||-joined union.
Implementations§
Source§impl Constraint
impl Constraint
Sourcepub fn parse(input: &str) -> Result<Self, ParseError>
pub fn parse(input: &str) -> Result<Self, ParseError>
Parse a Composer constraint string.
§Panics
Doesn’t: the internal .unwrap()s reach parsed.into_iter().next()
only when parsed.len() == 1 was just checked.
Sourcepub fn matches(&self, version: &Version) -> bool
pub fn matches(&self, version: &Version) -> bool
Return whether version satisfies this constraint.
Differs from version.compare(op, target) in the
prerelease-vs-stable edge case: when version is a prerelease
(e.g. 1.2.3-beta) and target is the stable form with the
same numeric body (1.2.3), Composer’s constraint engine
treats them as Equal rather than the normal “prerelease <
stable” ordering. This is what makes 1.2.3-beta satisfy
^1.2.3 and not satisfy <1.2.3.
Sourcepub fn lower_bound(&self) -> Bound
pub fn lower_bound(&self) -> Bound
The lowest version this constraint admits, as a Bound. Port
of Constraint::getLowerBound + MultiConstraint::extractBounds
(commit 09af5e8):
- atomic
==/>=→ inclusive bound at the version;>→ exclusive;</<=/!=→Bound::zero; adev-branch reference →Bound::zero(Composer’sstrpos(... 'dev-') === 0short-circuit). And(conjunctive) → the greatest of the members’ lower bounds;Or(disjunctive) → the least.
Any (* / x) is Bound::zero, matching
MatchAllConstraint.
Sourcepub fn upper_bound(&self) -> Bound
pub fn upper_bound(&self) -> Bound
The highest version this constraint admits, as a Bound.
Mirror of Constraint::lower_bound on the upper side:
==/<= → inclusive; < → exclusive; >/>=/!=/* →
Bound::positive_infinity. And → the least of the members’
upper bounds; Or → the greatest.
Sourcepub fn intersects(&self, other: &Constraint) -> bool
pub fn intersects(&self, other: &Constraint) -> bool
Whether self and other admit at least one common version —
i.e. their version intervals overlap. Used by the autoloader’s
platform_check.php generator to honor replace/provide of an
extension (Composer’s $provided->matches($link->getConstraint())).
Or is the union of its members, so it intersects other iff
any member does. Everything else reduces to a single contiguous
interval, so the two overlap iff max(lowers) <= min(uppers)
(with endpoint inclusivity deciding the touching case).
Trait Implementations§
Source§impl Clone for Constraint
impl Clone for Constraint
Source§fn clone(&self) -> Constraint
fn clone(&self) -> Constraint
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for Constraint
impl Debug for Constraint
impl Eq for Constraint
Source§impl PartialEq for Constraint
impl PartialEq for Constraint
Source§fn eq(&self, other: &Constraint) -> bool
fn eq(&self, other: &Constraint) -> bool
self and other values to be equal, and is used by ==.