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: TThe 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: TThe 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: TThe 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 + FromStr> Version<T>
impl<T: Ord + FromStr> Version<T>
Sourcepub fn from_string(version: &str) -> Option<Self>
pub fn from_string(version: &str) -> Option<Self>
Creates a Version<T> from a string in the major.minor.patch[+build] format.
Returns None if the string does not contain exactly three dot-separated segments
for the core version or if any component fails to parse into T.
§Examples
use simple_version::Version;
let version = Version::<u32>::from_string("1.2.3").unwrap();
assert_eq!(version, Version::new(1, 2, 3));
let version_with_build = Version::<u32>::from_string("1.2.3+4").unwrap();
assert_eq!(version_with_build, Version::new(1, 2, 3).build(4));Trait Implementations§
Source§impl<T: Ord + Ord> Ord for Version<T>
impl<T: Ord + Ord> Ord for Version<T>
1.21.0 · Source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
Compares and returns the maximum of two values. Read more
Source§impl<T: PartialOrd + Ord> PartialOrd for Version<T>
impl<T: PartialOrd + Ord> PartialOrd for Version<T>
impl<T: Copy + Ord> Copy for Version<T>
impl<T: Eq + Ord> Eq for Version<T>
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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more