pub struct Version { /* private fields */ }
Expand description
Represents a version and compatibility rules.
Implementations§
Source§impl Version
impl Version
Sourcepub const fn new(major: u64, minor: u64, patch: u64) -> Self
pub const fn new(major: u64, minor: u64, patch: u64) -> Self
Creates a new version in the form major.minor.patch
with a ruleset that is used to check
other versions such that >=0.1.2, <0.2.0
or >=1.2.3, <2
depending on whether or not the
major version is 0
.
use distant_net::common::Version;
// Matching versions are compatible
let a = Version::new(1, 2, 3);
let b = Version::new(1, 2, 3);
assert!(a.is_compatible_with(&b));
// Version 1.2.3 is compatible with 1.2.4, but not the other way
let a = Version::new(1, 2, 3);
let b = Version::new(1, 2, 4);
assert!(a.is_compatible_with(&b));
assert!(!b.is_compatible_with(&a));
// Version 1.2.3 is compatible with 1.3.0, but not 2
let a = Version::new(1, 2, 3);
assert!(a.is_compatible_with(&Version::new(1, 3, 0)));
assert!(!a.is_compatible_with(&Version::new(2, 0, 0)));
// Version 0.1.2 is compatible with 0.1.3, but not the other way
let a = Version::new(0, 1, 2);
let b = Version::new(0, 1, 3);
assert!(a.is_compatible_with(&b));
assert!(!b.is_compatible_with(&a));
// Version 0.1.2 is not compatible with 0.2
let a = Version::new(0, 1, 2);
let b = Version::new(0, 2, 0);
assert!(!a.is_compatible_with(&b));
assert!(!b.is_compatible_with(&a));
Sourcepub fn is_compatible_with(&self, other: &Self) -> bool
pub fn is_compatible_with(&self, other: &Self) -> bool
Returns true if this version is compatible with another version.
Sourcepub const fn from_be_bytes(bytes: [u8; 24]) -> Self
pub const fn from_be_bytes(bytes: [u8; 24]) -> Self
Converts from a collection of bytes into a version using the byte form major/minor/patch using big endian.
Sourcepub const fn to_be_bytes(&self) -> [u8; 24]
pub const fn to_be_bytes(&self) -> [u8; 24]
Converts the version into a byte form of major/minor/patch using big endian.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Version
impl RefUnwindSafe for Version
impl Send for Version
impl Sync for Version
impl Unpin for Version
impl UnwindSafe for Version
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