pub struct Version {
pub major: u64,
pub minor: u64,
pub patch: u64,
/* private fields */
}Expand description
A parsed Semantic Version, optionally scoped to a context
(npm:react@18.2.0).
Ordering follows the specification’s precedence rules: pre-releases rank
below their release and builds rank above it (1.0.0-rc < 1.0.0 < 1.0.0+build). The context never participates in precedence or equality.
A release is three integers; the pre-release, build and context of the
versions that have them live behind one pointer, so a Version is 32
bytes and plain releases parse without allocating.
Fields§
§major: u64Major version.
minor: u64Minor version.
patch: u64Patch version.
Implementations§
Source§impl Version
impl Version
Sourcepub fn new(major: u64, minor: u64, patch: u64) -> Self
pub fn new(major: u64, minor: u64, patch: u64) -> Self
Create a normal version major.minor.patch.
Sourcepub fn pre(&self) -> &Identifiers
pub fn pre(&self) -> &Identifiers
Pre-release identifiers (empty for a normal version).
Sourcepub fn build(&self) -> &Identifiers
pub fn build(&self) -> &Identifiers
Build identifiers, as written (empty when there is no build).
Sourcepub fn with_pre(self, pre: Identifiers) -> Self
pub fn with_pre(self, pre: Identifiers) -> Self
This version with pre as its pre-release.
Sourcepub fn with_build(self, build: Identifiers) -> Self
pub fn with_build(self, build: Identifiers) -> Self
This version with build as its build.
Sourcepub fn with_context(self, context: Option<&str>) -> Self
pub fn with_context(self, context: Option<&str>) -> Self
This version scoped to context (or to none).
Sourcepub fn parse(input: &str) -> Result<Self, Error>
pub fn parse(input: &str) -> Result<Self, Error>
Parse a version, optionally context-qualified (npm:react@1.2.3).
There is no coercion: v1.2.3 and 1.2 are errors.
Sourcepub fn is_prerelease(&self) -> bool
pub fn is_prerelease(&self) -> bool
True if this is a pre-release.
Sourcepub fn without_build(&self) -> Version
pub fn without_build(&self) -> Version
The version with its build removed (context kept).