[−][src]Struct dia_semver::Semver
Semver.
Concepts
Strict parser
- Does not allow leading/trailing white spaces.
- All 3 version numbers are required: major, minor, patch.
Tolerant parser
- Ignores leading/trailing white spaces.
- Minor and patch version numbers are optional.
This mode is added by the crate author, it's not described in official specification.
Usage
A semver instance should always be valid. For this reason, it does not expose internal fields (where the user can make new instance directly). Instead, it provides helper functions:
new()
makes new instance from raw input version numbers.parse()
and::parse_*()
use strict parser, while::from_*()
are more tolerant.
Since Rust encourages the use of immutable variables, a semver instance should not be changed. Once made, there are no
functions which help you change its fields. So let mut
is discouraged. However there are useful functions to help you make new semver
from an existing one: new_major()
, new_minor()
, new_patch()
...
Others might also come in handy: is_stable()
, is_early()
.
Methods
impl Semver
[src]
pub const MAX_INPUT_STR_LEN: u16
[src]
pub const fn new(major: u64, minor: u64, patch: u64) -> Semver
[src]
Makes new semver from raw input version numbers
This function does not support pre-release and build metadata -- which are required to be parsed. For convenience, it returns a direct
instance, not a Result<Semver>
. If you need pre-release and/or build metadata, you can use parse()
.
pub fn parse<S>(s: S) -> Result<Semver> where
S: AsRef<str>,
[src]
S: AsRef<str>,
Parses input string to make a new semver
- Minor and patch version numbers are required.
- Leading/trailing white spaces are not allowed.
For convenience, you can use from_str()
implemented from FromStr
trait. It uses tolerant
parser, in which:
- Minor and patch version numbers are optional.
- Leading/trailing white spaces are ignored.
Examples
use std::str::FromStr; use dia_semver::Semver; assert_eq!(Semver::parse("1.2.3").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 parse_os_str<S>(s: S) -> Result<Semver> where
S: AsRef<OsStr>,
[src]
S: AsRef<OsStr>,
Parses an &OsStr
This function uses strict parser.
pub fn from_os_str<S>(s: S) -> Result<Semver> where
S: AsRef<OsStr>,
[src]
S: AsRef<OsStr>,
Parses an &OsStr
This function uses tolerant parser.
pub fn parse_c_str<S>(s: S) -> Result<Semver> where
S: AsRef<CStr>,
[src]
S: AsRef<CStr>,
Parses a &CStr
This function uses strict parser.
pub fn from_c_str<S>(s: S) -> Result<Semver> where
S: AsRef<CStr>,
[src]
S: AsRef<CStr>,
Parses a &CStr
This function uses tolerant parser.
pub fn major(&self) -> u64
[src]
pub fn minor(&self) -> u64
[src]
pub fn patch(&self) -> u64
[src]
pub fn build_metadata(&self) -> Option<&str>
[src]
pub fn pre_release(&self) -> Option<&str>
[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
Notes:
- Case is ignored.
- If it returns
None
, it means the semver doesn't have a pre-release.
Examples
use std::str::FromStr; use dia_semver::{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"), Some(PreRelease::Other) => println!("Other"), None => println!("Not available"), };
pub fn compatible_with(&self, other: &Self) -> bool
[src]
Checks to see if this semver is compatible with one other
Two semvers are compatible with each other if one of these conditions is true:
- They have same major version, which must be larger than
0
. - If both major versions are
0
, they must have exactly these same components: major, minor, patch, pre-release.
Examples
use std::str::FromStr; use dia_semver::Semver; assert!(Semver::new(1, 0, 1).compatible_with(&Semver::new(1, 2, 3))); assert!(Semver::new(1, 0, 1).compatible_with(&Semver::new(1, 99, 9))); assert!(Semver::new(1, 0, 1).compatible_with(&Semver::new(2, 0, 0)) == false); assert!(Semver::new(0, 0, 1).compatible_with(&Semver::new(0, 2, 0)) == false); assert!(Semver::new(0, 0, 1).compatible_with(&Semver::from_str("0.0.1-abc").unwrap()) == false); assert!(Semver::new(0, 0, 1).compatible_with(&Semver::from_str("0.0.1+abc").unwrap()));
pub fn new_major(&self) -> Option<Semver>
[src]
Makes new semver with major version incremented by 1
Notes
- Pre-release and build metadata will be dropped.
checked_add()
will be used. So if overflow happens,None
is returned.
Examples
use std::str::FromStr; use dia_semver::Semver; assert_eq!(Semver::from_str("1.2.3-abc+xyz").unwrap().new_major().unwrap().to_string(), "2.0.0");
pub fn new_minor(&self) -> Option<Semver>
[src]
Makes new semver with minor version incremented by 1
Notes
- Pre-release and build metadata will be dropped.
checked_add()
will be used. So if overflow happens,None
is returned.
Examples
use std::str::FromStr; use dia_semver::Semver; assert_eq!(Semver::from_str("1.2.3-abc+xyz").unwrap().new_minor().unwrap().to_string(), "1.3.0");
pub fn new_patch(&self) -> Option<Semver>
[src]
Makes new semver with patch version incremented by 1
Notes
- Pre-release and build metadata will be dropped.
checked_add()
will be used. So if overflow happens,None
is returned.
Examples
use std::str::FromStr; use dia_semver::Semver; assert_eq!(Semver::from_str("1.2.3-abc+xyz").unwrap().new_patch().unwrap().to_string(), "1.2.4");
pub fn new_pre_release<S>(
&self,
pre_release: S,
keep_build_metadata: bool
) -> Result<Semver> where
S: AsRef<str>,
[src]
&self,
pre_release: S,
keep_build_metadata: bool
) -> Result<Semver> where
S: AsRef<str>,
Makes new semver with same version numbers, but new pre-release and/or same build metadata
pre_release
should not include leading character -
; it will be added automatically.
Examples
use std::str::FromStr; use dia_semver::Semver; assert_eq!( Semver::from_str("1.2.3-alpha.1+abc").unwrap() .new_pre_release("alpha.2", false).unwrap() .to_string(), "1.2.3-alpha.2" );
pub fn new_build_metadata<S>(
&self,
build_metadata: S,
keep_pre_release: bool
) -> Result<Semver> where
S: AsRef<str>,
[src]
&self,
build_metadata: S,
keep_pre_release: bool
) -> Result<Semver> where
S: AsRef<str>,
Makes new semver with same version numbers, but new build metadata and/or same pre-release
build_metadata
should not include leading character +
; it will be added automatically.
Examples
use std::str::FromStr; use dia_semver::Semver; assert_eq!( Semver::from_str("1.2.3-alpha.1+abc").unwrap() .new_build_metadata("xyz", false).unwrap() .to_string(), "1.2.3+xyz" );
Trait Implementations
impl Clone for Semver
[src]
impl Debug for Semver
[src]
impl Default for Semver
[src]
impl Display for Semver
[src]
impl Eq for Semver
[src]
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 input string via tolerant parser to make a new semver
- Minor and patch version numbers are optional.
- Leading/trailing white spaces are ignored.
For strict parser, see parse()
.
impl Hash for Semver
[src]
fn hash<H: Hasher>(&self, state: &mut H)
[src]
fn hash_slice<H>(data: &[Self], state: &mut H) where
H: Hasher,
1.3.0[src]
H: Hasher,
impl Ord for Semver
[src]
fn cmp(&self, other: &Semver) -> Ordering
[src]
fn max(self, other: Self) -> Self
1.21.0[src]
fn min(self, other: Self) -> Self
1.21.0[src]
fn clamp(self, min: Self, max: Self) -> Self
[src]
impl PartialEq<Semver> for Semver
[src]
impl PartialOrd<Semver> for Semver
[src]
fn partial_cmp(&self, other: &Semver) -> Option<Ordering>
[src]
#[must_use]
fn lt(&self, other: &Rhs) -> bool
1.0.0[src]
#[must_use]
fn le(&self, other: &Rhs) -> bool
1.0.0[src]
#[must_use]
fn gt(&self, other: &Rhs) -> bool
1.0.0[src]
#[must_use]
fn ge(&self, other: &Rhs) -> bool
1.0.0[src]
impl StructuralEq for Semver
[src]
Auto Trait Implementations
impl RefUnwindSafe for Semver
impl Send for Semver
impl Sync for Semver
impl Unpin for Semver
impl UnwindSafe for Semver
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
fn to_owned(&self) -> T
[src]
fn clone_into(&self, target: &mut T)
[src]
impl<T> ToString for T where
T: Display + ?Sized,
[src]
T: Display + ?Sized,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,