Semver

Struct Semver 

Source
pub struct Semver;
Expand description

Provides convenient methods for version comparison, constraint matching, and sorting.

Implementations§

Source§

impl Semver

Source

pub fn satisfies(version: &str, constraints: &str) -> Result<bool>

Check if a version satisfies a constraint string.

§Arguments
  • version - Version string to check
  • constraints - Constraint expression (e.g., “^1.0”, “>=2.0 <3.0”, “~1.2 || ^2.0”)
§Errors

Returns an error if the version or constraint string is invalid.

§Examples
use semver_php::Semver;

assert!(Semver::satisfies("1.2.3", "^1.0").unwrap());
assert!(Semver::satisfies("1.2.3", ">=1.0 <2.0").unwrap());
assert!(!Semver::satisfies("2.0.0", "^1.0").unwrap());
Source

pub fn satisfied_by(versions: &[&str], constraints: &str) -> Result<Vec<String>>

Filter a list of versions to those that satisfy a constraint.

§Arguments
  • versions - List of version strings
  • constraints - Constraint expression
§Errors

Returns an error if any version or the constraint string is invalid.

§Examples
use semver_php::Semver;

let versions = vec!["1.0", "1.2", "2.0", "3.0"];
let satisfied = Semver::satisfied_by(&versions, "~1.0").unwrap();
assert_eq!(satisfied, vec!["1.0", "1.2"]);
Source

pub fn sort(versions: &[&str]) -> Result<Vec<String>>

Sort versions in ascending order.

§Errors

Returns an error if any version string is invalid.

§Examples
use semver_php::Semver;

let versions = vec!["1.0", "0.1", "3.2.1", "2.4.0"];
let sorted = Semver::sort(&versions).unwrap();
assert_eq!(sorted, vec!["0.1", "1.0", "2.4.0", "3.2.1"]);
Source

pub fn rsort(versions: &[&str]) -> Result<Vec<String>>

Sort versions in descending order.

§Errors

Returns an error if any version string is invalid.

§Examples
use semver_php::Semver;

let versions = vec!["1.0", "0.1", "3.2.1", "2.4.0"];
let sorted = Semver::rsort(&versions).unwrap();
assert_eq!(sorted, vec!["3.2.1", "2.4.0", "1.0", "0.1"]);

Auto Trait Implementations§

§

impl Freeze for Semver

§

impl RefUnwindSafe for Semver

§

impl Send for Semver

§

impl Sync for Semver

§

impl Unpin for Semver

§

impl UnwindSafe for Semver

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