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

Full specification: https://semver.org

Fields

Pre-release.

This does not contain the leading character -. However calling Semver.to_string() will always have that character displayed.

Build metadata.

This does not contain the leading character +. However calling Semver.to_string() will always have that character displayed.

Methods

impl Semver
[src]

[src]

Parses input string to make a new semver.

Rules:

  • If strict is true:

    • Minor and patch version numbers are required.
    • Leading/trailing while spaces are not allowed.
  • If strict is false:

    • 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");

[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().

[src]

Parses an &OsStr.

This function calls ::parse() with true passed to strict.

[src]

Parses an &OsStr.

This function calls ::parse() with false passed to strict.

[src]

Parses a &CStr.

This function calls ::parse() with true passed to strict.

[src]

Parses a &CStr.

This function calls ::parse() with false passed to strict.

[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.

[src]

[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"),
}

[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");

[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");

[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]

[src]

Formats the value using the given formatter. Read more

impl Eq for Semver
[src]

impl PartialEq for Semver
[src]

[src]

This method tests for self and other values to be equal, and is used by ==. Read more

1.0.0
[src]

This method tests for !=.

impl Ord for Semver
[src]

[src]

This method returns an Ordering between self and other. Read more

1.21.0
[src]

Compares and returns the maximum of two values. Read more

1.21.0
[src]

Compares and returns the minimum of two values. Read more

impl PartialOrd for Semver
[src]

[src]

This method returns an ordering between self and other values if one exists. Read more

1.0.0
[src]

This method tests less than (for self and other) and is used by the < operator. Read more

1.0.0
[src]

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more

1.0.0
[src]

This method tests greater than (for self and other) and is used by the > operator. Read more

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]

[src]

Feeds this value into the given [Hasher]. Read more

1.3.0
[src]

Feeds a slice of this type into the given [Hasher]. Read more

impl FromStr for Semver
[src]

The associated error which can be returned from parsing.

[src]

Parses a string s to return a value of this type. Read more

impl Display for Semver
[src]

[src]

Formats the value using the given formatter. Read more

Auto Trait Implementations

impl Send for Semver

impl Sync for Semver