Skip to main content

Constraint

Enum Constraint 

Source
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.

Fields

§version: Version
§explicit_lower_bound: bool
§

And(Vec<Constraint>)

Whitespace-or-comma-joined intersection.

§

Or(Vec<Constraint>)

||-joined union.

Implementations§

Source§

impl Constraint

Source

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.

Source

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.

Source

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; a dev- branch reference → Bound::zero (Composer’s strpos(... 'dev-') === 0 short-circuit).
  • And (conjunctive) → the greatest of the members’ lower bounds; Or (disjunctive) → the least.

Any (* / x) is Bound::zero, matching MatchAllConstraint.

Source

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.

Source

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

Source§

fn clone(&self) -> Constraint

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 Constraint

Source§

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

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

impl Eq for Constraint

Source§

impl PartialEq for Constraint

Source§

fn eq(&self, other: &Constraint) -> 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 StructuralPartialEq for Constraint

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, 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.