Struct Version

Source
pub struct Version<T: Ord> {
    pub major: T,
    pub minor: T,
    pub patch: T,
    pub build: Option<T>,
}
Expand description

A struct that represents a version consisting of major, minor, patch, and an optional build number.

The generic parameter T specifies the numerical type to use for each version component.


§Examples

Creating a version without a build number:

use simple_version::Version;

let version: Version<u32> = Version::new(1, 2, 3);

Creating a version with a build number:

use simple_version::Version;

let version: Version<u32> = Version::new(1, 2, 3).build(4);

Fields§

§major: T

The major version component.


§Examples

use simple_version::Version;

let mut version = Version::<u32>::new(1, 2, 3);
 
// read major version
println!("{}", version.major);
 
// set major version
version.major = 4;
§minor: T

The minor version component.


§Examples

use simple_version::Version;
 
let mut version = Version::<u32>::new(1, 2, 3);
 
// read minor version
println!("{}", version.minor);
 
// set minor version
version.minor = 4;
§patch: T

The patch version component.


§Examples

use simple_version::Version;
 
let mut version = Version::<u32>::new(1, 2, 3);
 
// read patch version
println!("{}", version.patch);
 
// set patch version
version.patch = 4;
§build: Option<T>

The optional build number.


§Examples

use simple_version::Version;
 
// version with a build number
let mut version = Version::<u32>::new(1, 2, 3).build(4);
 
// read build number
if let Some(build) = version.build {
    println!("{}", build);
}
 
// set build number
version.build = Some(5);

Implementations§

Source§

impl<T: Ord> Version<T>

Source

pub fn new(major: T, minor: T, patch: T) -> Version<T>

Creates a new Version<T> without a build number.


§Arguments
  • major: the major version component
  • minor: the minor version component
  • patch: the patch version component

§Examples
use simple_version::Version;
 
let version: Version<u32> = Version::new(1, 2, 3);
Source

pub fn build(self, build: T) -> Version<T>

Adds a build number to the existing version object and returns it.


§Arguments
  • build: the build number

§Examples
use simple_version::Version;
 
let version: Version<u32> = Version::new(1, 2, 3).build(4);

Trait Implementations§

Source§

impl<T: Debug + Ord> Debug for Version<T>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<T: Ord + Display> Display for Version<T>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<T: Ord + Ord> Ord for Version<T>

Source§

fn cmp(&self, other: &Version<T>) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 · Source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · Source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · Source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized,

Restrict a value to a certain interval. Read more
Source§

impl<T: PartialEq + Ord> PartialEq for Version<T>

Source§

fn eq(&self, other: &Version<T>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<T: PartialOrd + Ord> PartialOrd for Version<T>

Source§

fn partial_cmp(&self, other: &Version<T>) -> Option<Ordering>

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

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · Source§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · Source§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · Source§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl<T: Eq + Ord> Eq for Version<T>

Source§

impl<T: Ord> StructuralPartialEq for Version<T>

Auto Trait Implementations§

§

impl<T> Freeze for Version<T>
where T: Freeze,

§

impl<T> RefUnwindSafe for Version<T>
where T: RefUnwindSafe,

§

impl<T> Send for Version<T>
where T: Send,

§

impl<T> Sync for Version<T>
where T: Sync,

§

impl<T> Unpin for Version<T>
where T: Unpin,

§

impl<T> UnwindSafe for Version<T>
where T: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

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

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.