#![no_std]
#![warn(missing_docs)]
#![deny(unsafe_code)]
#![warn(clippy::pedantic)]
#![allow(clippy::must_use_candidate)]
#![allow(clippy::return_self_not_must_use)]
extern crate alloc;
use core::fmt;
#[derive(Clone, Copy)]
pub struct ListVersion {
pub major: u16,
pub minor: u16,
pub patch: u16,
}
impl ListVersion {
#[inline]
fn get_maj(self) -> u16 {
if self.experimental() { self.minor }
else { self.major }
}
#[inline]
fn get_min(self) -> u16 {
if self.experimental() { self.patch }
else { self.minor }
}
#[inline]
pub fn experimental(self) -> bool {
self.major == 0
}
pub fn compatible(self, other: ListVersion) -> bool {
if self.get_maj() == other.get_maj() && self.get_min() > other.get_min() {
true
} else {
self.get_min() == other.get_min() && self.patch >= other.patch
}
}
}
macro_rules! version {
($major: literal, $minor: literal, $patch: literal) => {
#[doc = "The current `ListVersion` of this module. "]
#[doc = concat!("(", $major, ".", $minor, ".", $patch, ")")]
#[doc = " See [its documentation](crate::ListVersion) for more information."]
pub const VERSION: crate::ListVersion = crate::ListVersion {
major: $major,
minor: $minor,
patch: $patch
};
};
}
impl fmt::Display for ListVersion {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "{}.{}.{}", self.major, self.minor, self.patch)
}
}
impl fmt::Debug for ListVersion {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
<Self as fmt::Display>::fmt(self, f)
}
}
#[cfg(feature = "stack")]
pub mod stack;
#[macro_use]
#[cfg(any(feature = "persistent", feature = "persistent_arc"))]
mod persistent_common;
#[cfg(feature = "persistent")]
pub mod persistent;
#[cfg(feature = "persistent_arc")]
pub mod persistent_arc;
#[cfg(test)]
mod tests {
use super::ListVersion;
#[test]
fn compatibility() {
let experimental = ListVersion {
major: 0,
minor: 1,
patch: 4,
};
let less_experimental = ListVersion {
major: 0,
minor: 1,
patch: 77,
};
assert!(less_experimental.compatible(experimental));
let one = ListVersion {
major: 1,
minor: 3,
patch: 4,
};
assert!(!one.compatible(experimental));
let two = ListVersion {
major: 2,
minor: 0,
patch: 0,
};
assert!(!one.compatible(two));
assert!(!two.compatible(one));
}
}