pub struct SchemaVersion {
pub major: u32,
pub minor: u32,
pub patch: u32,
}Expand description
Schema version identifier.
Represents the version of a type’s schema using semantic versioning.
§Examples
use hedl_core::schema_version::SchemaVersion;
// Create a version
let v1 = SchemaVersion::new(1, 0, 0);
let v2 = SchemaVersion::new(1, 1, 0);
// Compare versions
assert!(v2 > v1);
assert!(v2.is_compatible_with(&v1));Fields§
§major: u32Major version (breaking changes)
minor: u32Minor version (backward-compatible additions)
patch: u32Patch version (bug fixes)
Implementations§
Source§impl SchemaVersion
impl SchemaVersion
Sourcepub const fn new(major: u32, minor: u32, patch: u32) -> Self
pub const fn new(major: u32, minor: u32, patch: u32) -> Self
Create a new schema version.
§Arguments
major- Major version numberminor- Minor version numberpatch- Patch version number
§Examples
use hedl_core::schema_version::SchemaVersion;
let version = SchemaVersion::new(1, 2, 3);
assert_eq!(version.major, 1);
assert_eq!(version.minor, 2);
assert_eq!(version.patch, 3);Sourcepub fn is_compatible_with(&self, other: &Self) -> bool
pub fn is_compatible_with(&self, other: &Self) -> bool
Check if this version is compatible with another version.
Compatibility rules:
- Same major version required
- This version’s minor must be >= other’s minor
§Arguments
other- The version to check compatibility with
§Returns
true if this schema can read data written for other
§Examples
use hedl_core::schema_version::SchemaVersion;
let v1_0 = SchemaVersion::new(1, 0, 0);
let v1_1 = SchemaVersion::new(1, 1, 0);
let v2_0 = SchemaVersion::new(2, 0, 0);
// v1.1 can read v1.0 data (backward compatible)
assert!(v1_1.is_compatible_with(&v1_0));
// v1.0 cannot read v1.1 data (missing new fields)
assert!(!v1_0.is_compatible_with(&v1_1));
// Different major versions are not compatible
assert!(!v2_0.is_compatible_with(&v1_0));Sourcepub fn is_breaking_from(&self, other: &Self) -> bool
pub fn is_breaking_from(&self, other: &Self) -> bool
Check if this is a breaking change from another version.
A breaking change occurs when the major version increases.
Sourcepub fn parse(s: &str) -> Option<Self>
pub fn parse(s: &str) -> Option<Self>
Parse a version string in “major.minor.patch” format.
§Arguments
s- Version string to parse
§Returns
Some(SchemaVersion) if parsing succeeds, None otherwise
§Examples
use hedl_core::schema_version::SchemaVersion;
let v = SchemaVersion::parse("1.2.3").unwrap();
assert_eq!(v, SchemaVersion::new(1, 2, 3));
// Short forms also work
let v = SchemaVersion::parse("1.2").unwrap();
assert_eq!(v, SchemaVersion::new(1, 2, 0));
let v = SchemaVersion::parse("1").unwrap();
assert_eq!(v, SchemaVersion::new(1, 0, 0));Trait Implementations§
Source§impl Clone for SchemaVersion
impl Clone for SchemaVersion
Source§fn clone(&self) -> SchemaVersion
fn clone(&self) -> SchemaVersion
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for SchemaVersion
impl Debug for SchemaVersion
Source§impl Default for SchemaVersion
impl Default for SchemaVersion
Source§impl Display for SchemaVersion
impl Display for SchemaVersion
Source§impl FromStr for SchemaVersion
Parse a schema version from a string.
impl FromStr for SchemaVersion
Parse a schema version from a string.
Source§impl Hash for SchemaVersion
impl Hash for SchemaVersion
Source§impl Ord for SchemaVersion
impl Ord for SchemaVersion
Source§fn cmp(&self, other: &SchemaVersion) -> Ordering
fn cmp(&self, other: &SchemaVersion) -> Ordering
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 PartialEq for SchemaVersion
impl PartialEq for SchemaVersion
Source§impl PartialOrd for SchemaVersion
impl PartialOrd for SchemaVersion
impl Copy for SchemaVersion
impl Eq for SchemaVersion
impl StructuralPartialEq for SchemaVersion
Auto Trait Implementations§
impl Freeze for SchemaVersion
impl RefUnwindSafe for SchemaVersion
impl Send for SchemaVersion
impl Sync for SchemaVersion
impl Unpin for SchemaVersion
impl UnwindSafe for SchemaVersion
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more