#[derive(Clone, Copy, PartialEq, Eq, Hash)]
pub struct SpecVersion {
major: u32,
minor: u32,
micro: u32,
}
impl SpecVersion {
pub const fn new(major: u32, minor: u32, micro: u32) -> SpecVersion {
SpecVersion {
major: major,
minor: minor,
micro: micro,
}
}
pub const fn major(&self) -> u32 {
self.major
}
pub const fn minor(&self) -> u32 {
self.minor
}
pub const fn micro(&self) -> u32 {
self.micro
}
}
impl std::fmt::Display for SpecVersion {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
write!(f, "v{}.{}.{}", self.major, self.minor, self.micro)
}
}
impl std::fmt::Debug for SpecVersion {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
write!(
f,
"SpecVersion({}.{}.{})",
self.major, self.minor, self.micro
)
}
}
impl Default for SpecVersion {
fn default() -> Self {
SpecVersion::new(0, 0, 0)
}
}
impl Ord for SpecVersion {
fn cmp(&self, other: &Self) -> std::cmp::Ordering {
if self.major != other.major {
self.major.cmp(&other.major)
} else if self.minor != other.minor {
self.minor.cmp(&other.minor)
} else {
self.micro.cmp(&other.micro)
}
}
}
impl PartialOrd for SpecVersion {
fn partial_cmp(&self, other: &Self) -> Option<std::cmp::Ordering> {
Some(self.cmp(other))
}
}