Struct dia_semver::Semver
[−]
[src]
pub struct Semver { pub major: u64, pub minor: u64, pub patch: u64, pub pre_release: Option<String>, pub build_metadata: Option<String>, // some fields omitted }
Semver.
Some concepts
- Strict parser does not allow leading/trailing while spaces; all 3 version numbers are required: major, minor, patch.
- Tolerant parser ignores leading/trailing while spaces. Minor and patch version numbers are optional. This mode is added by the crate author, it's not described in official specification.
- A
Semver
instance should always be valid. For this reason, it does not support making new instance directly. Instead, it provides functions.
Usage
::new()
makes new instance from raw input version numbers.::parse()
and::parse_*()
use strict parser, while::from_*()
are more tolerant.- These functions might be useful:
is_stable()
,is_early()
,parse_pre_release()
,new_major()
,new_minor()
,new_patch()
...
Full specification: https://semver.org
Fields
major: u64
minor: u64
patch: u64
pre_release: Option<String>
Pre-release.
This does not contain the leading character -
. However calling Semver.to_string()
will always have that
character displayed.
build_metadata: Option<String>
Build metadata.
This does not contain the leading character +
. However calling Semver.to_string()
will always have that
character displayed.
Methods
impl Semver
[src]
pub fn parse(s: &str, strict: bool) -> Result<Semver, ParseSemverError>
[src]
Parses input string to make a new semver.
Rules:
-
If
strict
istrue
:- Minor and patch version numbers are required.
- Leading/trailing while spaces are not allowed.
-
If
strict
isfalse
:- Minor and patch version numbers are optional.
- Leading/trailing while spaces are ignored.
For convenience, you can use ::from_str(&str)
implemented from FromStr
trait. It calls this function with
false
passed to strict
.
Examples
use std::str::FromStr; use dia_semver::Semver; assert_eq!(Semver::parse("1.2.3", true).unwrap().to_string(), "1.2.3"); assert_eq!(Semver::from_str("\t 1-a.b.c \r\n").unwrap().to_string(), "1.0.0-a.b.c");
pub fn new(major: u64, minor: u64, patch: u64) -> Semver
[src]
Makes new semver from raw input version numbers.
This function doesn't support pre-release and build metadata, since a semver object should always be valid. And for convenience, this
function returns a direct instance (not via Result<Semver, ParseSemverError>
). If you need pre-release and/or build metadata, you
can use ::parse()
.
pub fn parse_os_str(s: &OsStr) -> Result<Semver, ParseSemverError>
[src]
pub fn from_os_str(s: &OsStr) -> Result<Semver, ParseSemverError>
[src]
pub fn parse_c_str(s: &CStr) -> Result<Semver, ParseSemverError>
[src]
pub fn from_c_str(s: &CStr) -> Result<Semver, ParseSemverError>
[src]
pub fn is_stable(&self) -> bool
[src]
Checks to see if the semver is stable.
A semver is stable if:
- It's not a pre-release.
- Its major version is larger than zero.
pub fn is_early(&self) -> bool
[src]
pub fn parse_pre_release(&self) -> Option<PreRelease>
[src]
Parses pre-release to see if it starts with some common phrases.
Note that case is ignored.
Examples
use std::str::FromStr; use dia_semver::Semver; use dia_semver::PreRelease; match Semver::from_str("1.2.3-hola").unwrap().parse_pre_release() { Some(PreRelease::Alpha) => println!("Alpha"), Some(PreRelease::Beta) => println!("Beta"), Some(PreRelease::RC) => println!("RC"), None => println!("Not supported yet"), }
pub fn new_major(&self) -> Semver
[src]
Makes new semver with major version incremented by 1
.
Pre-release and build metadata will be dropped.
Examples
use std::str::FromStr; use dia_semver::Semver; assert_eq!(Semver::from_str("1.2.3-abc+xyz").unwrap().new_major().to_string(), "2.0.0");
pub fn new_minor(&self) -> Semver
[src]
Makes new semver with minor version incremented by 1
.
Pre-release and build metadata will be dropped.
Examples
use std::str::FromStr; use dia_semver::Semver; assert_eq!(Semver::from_str("1.2.3-abc+xyz").unwrap().new_minor().to_string(), "1.3.0");
pub fn new_patch(&self) -> Semver
[src]
Makes new semver with patch version incremented by 1
.
Pre-release and build metadata will be dropped.
Examples
use std::str::FromStr; use dia_semver::Semver; assert_eq!(Semver::from_str("1.2.3-abc+xyz").unwrap().new_patch().to_string(), "1.2.4");
Trait Implementations
impl Debug for Semver
[src]
fn fmt(&self, __arg_0: &mut Formatter) -> Result
[src]
Formats the value using the given formatter. Read more
impl Eq for Semver
[src]
impl PartialEq for Semver
[src]
fn eq(&self, other: &Semver) -> bool
[src]
This method tests for self
and other
values to be equal, and is used by ==
. Read more
fn ne(&self, other: &Rhs) -> bool
1.0.0[src]
This method tests for !=
.
impl Ord for Semver
[src]
fn cmp(&self, other: &Semver) -> Ordering
[src]
This method returns an Ordering
between self
and other
. Read more
fn max(self, other: Self) -> Self
1.21.0[src]
Compares and returns the maximum of two values. Read more
fn min(self, other: Self) -> Self
1.21.0[src]
Compares and returns the minimum of two values. Read more
impl PartialOrd for Semver
[src]
fn partial_cmp(&self, other: &Semver) -> Option<Ordering>
[src]
This method returns an ordering between self
and other
values if one exists. Read more
fn lt(&self, other: &Rhs) -> bool
1.0.0[src]
This method tests less than (for self
and other
) and is used by the <
operator. Read more
fn le(&self, other: &Rhs) -> bool
1.0.0[src]
This method tests less than or equal to (for self
and other
) and is used by the <=
operator. Read more
fn gt(&self, other: &Rhs) -> bool
1.0.0[src]
This method tests greater than (for self
and other
) and is used by the >
operator. Read more
fn ge(&self, other: &Rhs) -> bool
1.0.0[src]
This method tests greater than or equal to (for self
and other
) and is used by the >=
operator. Read more
impl Hash for Semver
[src]
fn hash<H: Hasher>(&self, state: &mut H)
[src]
Feeds this value into the given [Hasher
]. Read more
fn hash_slice<H>(data: &[Self], state: &mut H) where
H: Hasher,
1.3.0[src]
H: Hasher,
Feeds a slice of this type into the given [Hasher
]. Read more
impl FromStr for Semver
[src]
type Err = ParseSemverError
The associated error which can be returned from parsing.
fn from_str(s: &str) -> Result<Self, Self::Err>
[src]
Parses a string s
to return a value of this type. Read more