pub struct Range { /* private fields */ }Expand description
A version range, e.g. ^1.0.0 or >=1.0.0 <2.0.0-0.
Its string form preserves the parsed comparator structure, but may differ from the original input when wildcards, build metadata, or unrestricted unions are simplified away.
§Examples
use js_semver::Range;
assert_eq!(Range::parse("^1.2.3").unwrap().to_string(), ">=1.2.3 <2.0.0-0");
assert_eq!(Range::parse("^1.2.3 || *").unwrap().to_string(), "*");
assert_eq!(Range::parse("1.x.x+experimental").unwrap().to_string(), ">=1.0.0 <2.0.0-0");Implementations§
Source§impl Range
impl Range
Sourcepub fn parse(s: &str) -> Result<Self, SemverError>
pub fn parse(s: &str) -> Result<Self, SemverError>
Parse a range string.
The parsed range is displayed in canonical comparator form.
§Examples
use js_semver::Range;
assert_eq!(Range::parse("^1.2.3").unwrap().to_string(), ">=1.2.3 <2.0.0-0");
assert_eq!(Range::parse(">=2.0.0").unwrap().to_string(), ">=2.0.0");§Errors
Returns SemverError if s is not a valid semver range string.
Sourcepub fn satisfies(&self, version: &Version) -> bool
pub fn satisfies(&self, version: &Version) -> bool
Returns true if the given Version satisfies this range.
This follows node-semver’s prerelease restriction rule: a prerelease
version only matches when the range contains a comparator with the same
major.minor.patch tuple and an explicit prerelease.
§Examples
use js_semver::{Range, Version};
let range = Range::parse("^1.2.3").unwrap();
assert!(range.satisfies(&Version::parse("1.5.0").unwrap()));
assert!(!range.satisfies(&Version::parse("2.0.0").unwrap()));Trait Implementations§
Auto Trait Implementations§
impl Freeze for Range
impl RefUnwindSafe for Range
impl Send for Range
impl Sync for Range
impl Unpin for Range
impl UnsafeUnpin for Range
impl UnwindSafe for Range
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more