Enum version_number::Version
source · pub enum Version {
Base(BaseVersion),
Full(FullVersion),
}
Expand description
A numbered version which is a two-component major.minor
version number,
or a three-component major.minor.patch
version number.
Variants§
Base(BaseVersion)
A two-component major.minor
version.
Full(FullVersion)
A three-component major.minor.patch
version.
Implementations§
source§impl Version
impl Version
sourcepub fn parse(input: &str) -> Result<Self, Error>
pub fn parse(input: &str) -> Result<Self, Error>
Parse a two- or three-component, major.minor
or major.minor.patch
respectively,
version number from a given input.
Returns a Error::ParserError
if it fails to parse.
sourcepub fn new_base_version(major: u64, minor: u64) -> Self
pub fn new_base_version(major: u64, minor: u64) -> Self
Create a new two-component major.minor
version number.
sourcepub fn new_full_version(major: u64, minor: u64, patch: u64) -> Self
pub fn new_full_version(major: u64, minor: u64, patch: u64) -> Self
Create a new three-component major.minor.patch
version number.
sourcepub fn major(&self) -> u64
pub fn major(&self) -> u64
Returns the major
version component.
Both the two- and three-component version number variants have a major version. This is the leading component.
sourcepub fn minor(&self) -> u64
pub fn minor(&self) -> u64
Returns the minor
version component.
Both the two- and three-component version number variants have a minor version. This is the middle component.
sourcepub fn patch(&self) -> Option<u64>
pub fn patch(&self) -> Option<u64>
Returns the patch
version component, if any.
A three component major.minor.patch
version will return a Some(<version>)
,
while a two component major.minor
version will return None
instead.
If it exists, it is the last component.
sourcepub fn map<U, F>(self, fun: F) -> Uwhere
F: FnOnce(Self) -> U,
pub fn map<U, F>(self, fun: F) -> Uwhere
F: FnOnce(Self) -> U,
Map a Version
to U
.
§Example
use version_number::{BaseVersion, FullVersion, Version};
// 🧑🔬
fn invert_version(v: Version) -> Version {
match v {
Version::Base(base) => Version::Base(BaseVersion::new(base.minor, base.major)),
Version::Full(full) => Version::Full(FullVersion::new(full.patch, full.minor, full.major))
}
}
let base_example = Version::Base(BaseVersion::new(1, 2));
let full_example = Version::Full(FullVersion::new(1, 2, 3));
assert_eq!(base_example.map(invert_version), Version::Base(BaseVersion::new(2, 1)));
assert_eq!(full_example.map(invert_version), Version::Full(FullVersion::new(3, 2, 1)));
sourcepub fn map_major<F>(self, fun: F) -> Self
pub fn map_major<F>(self, fun: F) -> Self
Map over the major
version component of the Version
.
§Example
use version_number::{BaseVersion, FullVersion, Version};
let base_example = Version::Base(BaseVersion::new(0, 0));
let full_example = Version::Full(FullVersion::new(0, 0, 0));
assert_eq!(base_example.map_major(|a| a + 1), Version::Base(BaseVersion::new(1, 0)));
assert_eq!(full_example.map_major(|a| a + 1), Version::Full(FullVersion::new(1, 0, 0)));
sourcepub fn map_minor<F>(self, fun: F) -> Self
pub fn map_minor<F>(self, fun: F) -> Self
Map over the minor
version component of the Version
.
§Example
use version_number::{BaseVersion, FullVersion, Version};
let base_example = Version::Base(BaseVersion::new(0, 0));
let full_example = Version::Full(FullVersion::new(0, 0, 0));
assert_eq!(base_example.map_minor(|a| a + 1), Version::Base(BaseVersion::new(0, 1)));
assert_eq!(full_example.map_minor(|a| a + 1), Version::Full(FullVersion::new(0, 1, 0)));
sourcepub fn map_patch<F>(self, fun: F) -> Self
pub fn map_patch<F>(self, fun: F) -> Self
Map over the patch
version component of the Version
.
If no patch
version exists (in case the Version
consists of two components),
then the original version is returned.
§Example
use version_number::{BaseVersion, FullVersion, Version};
let base_example = Version::Base(BaseVersion::new(0, 0));
let full_example = Version::Full(FullVersion::new(0, 0, 0));
assert_eq!(base_example.map_patch(|a| a + 1), Version::Base(BaseVersion::new(0, 0)));
assert_eq!(full_example.map_patch(|a| a + 1), Version::Full(FullVersion::new(0, 0, 1)));