[]Struct lenient_semver::VersionLite

pub struct VersionLite<'input> {
    pub major: u64,
    pub minor: u64,
    pub patch: u64,
    pub additional: Vec<u64>,
    pub pre: Vec<&'input str>,
    pub build: Vec<&'input str>,
}

Represents a lenient semantic version number.

The version is bound to the lifetime of the input string.

Fields

major: u64

The major version.

minor: u64

The minor version.

patch: u64

The patch version.

additional: Vec<u64>

additional version numbers.

pre: Vec<&'input str>

The pre-release metadata.

build: Vec<&'input str>

The build metadata.

Implementations

impl<'input> Version<'input>

pub const fn empty() -> Version<'input>

Constructs a new, empty version

Examples

let version = Version::empty();
assert_eq!(version.to_string(), "0.0.0")

pub const fn new(major: u64, minor: u64, patch: u64) -> Version<'input>

Constructs a new version out of the three regular version components

Examples

let version = Version::new(1, 2, 3);
assert_eq!(version.to_string(), "1.2.3")

pub fn parse(input: &'input str) -> Result<Version<'input>, Error<'input>>

Parse a string slice into a Version.

This parser does not require semver-specification conformant input and is more lenient in what it allows. For more information, see lenient_semver_parser.

Examples


let version = Version::parse("v1.2.3.4.5+build.42");
assert!(version.is_ok());

pub fn bump_major(&mut self)

Bumps the major version.

Sets minor, patch, and additional numbers to 0, removes pre-release and build identifier.

Examples


let mut version = Version::parse("1.2.3.4.5-pre+build").unwrap();
version.bump_major();
assert_eq!(version.to_string(), "2.0.0.0.0");

pub fn bumped_major<'a>(&self) -> Version<'a>

Returns a new version with the major version bumped.

Sets minor, patch, and additional numbers to 0, removes pre-release and build identifier. The lifetime for the resulting version can differ from the lifetime of this version.

Examples


let version = Version::parse("1.2.3.4.5-pre+build").unwrap();
assert_eq!(version.bumped_major().to_string(), "2.0.0.0.0");

pub fn bump_minor(&mut self)

Bumps the minor version.

Sets patch and additional numbers to 0, removes pre-release and build identifier.

Examples


let mut version = Version::parse("1.2.3.4.5-pre+build").unwrap();
version.bump_minor();
assert_eq!(version.to_string(), "1.3.0.0.0");

pub fn bumped_minor<'a>(&self) -> Version<'a>

Returns a new version with the minor version bumped.

Sets patch and additional numbers to 0, removes pre-release and build identifier. The lifetime for the resulting version can differ from the lifetime of this version.

Examples


let version = Version::parse("1.2.3.4.5-pre+build").unwrap();
assert_eq!(version.bumped_minor().to_string(), "1.3.0.0.0");

pub fn bump_patch(&mut self)

Bumps the patch version.

Sets any additional numbers to 0, removes pre-release and build identifier.

Examples


let mut version = Version::parse("1.2.3.4.5-pre+build").unwrap();
version.bump_patch();
assert_eq!(version.to_string(), "1.2.4.0.0");

pub fn bumped_patch<'a>(&self) -> Version<'a>

Returns a new version with the patch version bumped.

Sets any additional numbers to 0, removes pre-release and build identifier. The lifetime for the resulting version can differ from the lifetime of this version.

Examples


let version = Version::parse("1.2.3.4.5-pre+build").unwrap();
assert_eq!(version.bumped_patch().to_string(), "1.2.4.0.0");

pub fn bump_additional(&mut self, index: usize)

Bumps any additional version.

Sets any following additional numbers to 0, removes pre-release and build identifier. If there are not enough additional numbers, only the pre-release and build identifier is removed.

Examples


let mut version = Version::parse("1.2.3.4.5-pre+build").unwrap();
version.bump_additional(0);
assert_eq!(version.to_string(), "1.2.3.5.0");

let mut version = Version::parse("1.2.3.4.5-pre+build").unwrap();
version.bump_additional(1);
assert_eq!(version.to_string(), "1.2.3.4.6");

let mut version = Version::parse("1.2.3.4.5-pre+build").unwrap();
version.bump_additional(2);
assert_eq!(version.to_string(), "1.2.3.4.5");

pub fn bumped_additional<'a>(&self, index: usize) -> Version<'a>

Returns a new version with the minor version bumped.

Sets patch and additional numbers to 0, removes pre-release and build identifier. The lifetime for the resulting version can differ from the lifetime of this version.

Examples


let version = Version::parse("1.2.3.4.5-pre+build").unwrap();
assert_eq!(version.bumped_additional(0).to_string(), "1.2.3.5.0");
assert_eq!(version.bumped_additional(1).to_string(), "1.2.3.4.6");
assert_eq!(version.bumped_additional(2).to_string(), "1.2.3.4.5");

pub fn is_pre_release(&self) -> bool

Returns true if this version has pre-release metadata, i.e. it represents a pre-release.

Examples


let version = Version::parse("1").unwrap();
assert!(!version.is_pre_release());

let version = Version::parse("1-pre").unwrap();
assert!(version.is_pre_release());

let version = Version::parse("1+build").unwrap();
assert!(!version.is_pre_release());

pub fn disassociate_metadata<'a>(
    self
) -> (Version<'a>, Vec<&'input str>, Vec<&'input str>)

Disassociate this Version by changing the lifetime to something new.

The returned is a copy of self without any metadata. Nothing in the new version references 'input, so we can change the lifetime to something else.

The existing identifiers for pre-release and build are returned as well, so that users can clone and re-add them.

Examples

use lenient_semver_parser::VersionBuilder;

let input = String::from("1-pre+build");
let version = Version::parse(&input).unwrap();

// couldn't drop input here
// drop(input);

let (mut version, pre, build) = version.disassociate_metadata::<'static>();

assert_eq!(vec!["pre"], pre);
assert_eq!(vec!["build"], build);

// now we can drop the input
drop(input);

// We can use the new version after it has be disassociated from `input`.
assert_eq!("1.0.0", version.to_string());

// only static metadata references are allowed now (because we said 'static earlier)
version.add_pre_release("pre2");
version.add_build("build2");

assert_eq!("1.0.0-pre2+build2", version.to_string());

Trait Implementations

impl<'input> Clone for Version<'input>

impl<'input> Debug for Version<'input>

impl<'_> Default for Version<'_>

impl<'de, 'input> Deserialize<'de> for Version<'input> where
    'de: 'input, 

impl<'_> Display for Version<'_>

impl<'input> Eq for Version<'input>

impl<'input> From<[u64; 1]> for Version<'input>

impl<'input> From<[u64; 2]> for Version<'input>

impl<'input> From<[u64; 3]> for Version<'input>

impl<'input> From<(u64, u64, u64)> for Version<'input>

impl<'input> From<(u64, u64)> for Version<'input>

impl<'input> From<u64> for Version<'input>

impl<'_> Hash for Version<'_>

impl<'_> Ord for Version<'_>

impl<'_> PartialEq<Version<'_>> for Version<'_>

impl<'_> PartialOrd<Version<'_>> for Version<'_>

impl<'_> Serialize for Version<'_>

impl<'input> StructuralEq for Version<'input>

impl<'input> TryFrom<&'input str> for Version<'input>

type Error = Error<'input>

The type returned in the event of a conversion error.

impl<'input> VersionBuilder<'input> for Version<'input>

type Out = Version<'input>

The return type of the final version.

Auto Trait Implementations

impl<'input> RefUnwindSafe for Version<'input>

impl<'input> Send for Version<'input>

impl<'input> Sync for Version<'input>

impl<'input> Unpin for Version<'input>

impl<'input> UnwindSafe for Version<'input>

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> DeserializeOwned for T where
    T: for<'de> Deserialize<'de>, 
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T> ToString for T where
    T: Display + ?Sized
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.