pub struct Version { /* private fields */ }Expand description
A semantic version, conformant to the semver spec.
Implementations§
Source§impl Version
impl Version
pub fn new( major: u64, minor: u64, patch: u64, pre_release: Vec<Identifier>, build: Vec<Identifier>, ) -> Self
pub fn build(&self) -> &[Identifier]
pub fn pre_release(&self) -> &[Identifier]
Sourcepub fn into_parts(self) -> VersionParts
pub fn into_parts(self) -> VersionParts
Consumes this version and returns owned components.
This moves build and prerelease identifiers out without cloning them.
use nodejs_semver::{Identifier, Version, VersionParts};
let version = Version::parse("1.2.3-alpha.1+build.7").unwrap();
let VersionParts {
major,
minor,
patch,
pre_release,
build,
} = version.into_parts();
assert_eq!((major, minor, patch), (1, 2, 3));
assert_eq!(
pre_release,
vec![Identifier::AlphaNumeric("alpha".into()), Identifier::Numeric(1)]
);
assert_eq!(
build,
vec![
Identifier::AlphaNumeric("build".into()),
Identifier::Numeric(7)
]
);Sourcepub fn satisfies_with_prerelease(
&self,
range: &Range,
include_prerelease: bool,
) -> bool
pub fn satisfies_with_prerelease( &self, range: &Range, include_prerelease: bool, ) -> bool
Sourcepub fn is_prerelease(&self) -> bool
pub fn is_prerelease(&self) -> bool
True is this Version has a prerelease component.
Sourcepub fn inc(
&self,
release: &str,
identifier: Option<&str>,
identifier_base: Option<IdentifierBase>,
) -> Result<Version, IncrementError>
pub fn inc( &self, release: &str, identifier: Option<&str>, identifier_base: Option<IdentifierBase>, ) -> Result<Version, IncrementError>
Sourcepub fn parse<S: AsRef<str>>(input: S) -> Result<Version, SemverError>
pub fn parse<S: AsRef<str>>(input: S) -> Result<Version, SemverError>
Parse a semver string into a Version.
use nodejs_semver::Version;
fn main() {
let v = Version::parse("1.2.3-rc.4").unwrap();
println!("{}", v);
}Sourcepub fn diff(&self, other: &Self) -> Option<VersionDiff>
pub fn diff(&self, other: &Self) -> Option<VersionDiff>
difference between two Versions by the release type,
or None if the Versions are the same.
use nodejs_semver::{Version, VersionDiff};
fn main() {
let v1 = Version::parse("1.2.3-rc.4").unwrap();
let v2 = Version::parse("1.2.3").unwrap();
let diff = v1.diff(&v2);
assert_eq!(diff, Some(VersionDiff::Patch));
}Trait Implementations§
impl Eq for Version
Source§impl Ord for Version
impl Ord for Version
1.21.0 (const: unstable) · Source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
Compares and returns the maximum of two values. Read more
Auto Trait Implementations§
impl Freeze for Version
impl RefUnwindSafe for Version
impl Send for Version
impl Sync for Version
impl Unpin for Version
impl UnsafeUnpin for Version
impl UnwindSafe for Version
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