use std::borrow::Cow;
pub const WALLET_STANDARD_VERSION: &str = "1.0.0";
#[derive(PartialEq, Eq, PartialOrd, Ord, Hash, Clone, Copy)]
pub struct SemverVersion {
major: u8,
minor: u8,
patch: u8,
}
impl SemverVersion {
pub fn new() -> Self {
Self::default()
}
pub fn set_major(mut self, major: u8) -> Self {
self.major = major;
self
}
pub fn set_minor(mut self, minor: u8) -> Self {
self.minor = minor;
self
}
pub fn set_patch(mut self, patch: u8) -> Self {
self.patch = patch;
self
}
pub fn major(&self) -> u8 {
self.major
}
pub fn minor(&self) -> u8 {
self.minor
}
pub fn patch(&self) -> u8 {
self.patch
}
pub fn stringify_version<'a>(&'a self) -> Cow<'a, str> {
Cow::Borrowed("")
+ Cow::Owned(self.major.to_string())
+ "."
+ Cow::Owned(self.minor.to_string())
+ "."
+ Cow::Owned(self.minor.to_string())
}
}
impl core::fmt::Debug for SemverVersion {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(
f,
"SemverVersion({}.{}.{})",
self.major, self.minor, self.patch
)
}
}
impl core::fmt::Display for SemverVersion {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "{}.{}.{}", self.major, self.minor, self.patch)
}
}
pub trait Version {
fn version(&self) -> SemverVersion {
SemverVersion {
major: 1,
minor: 0,
patch: 0,
}
}
}
impl Version for SemverVersion {}
impl Default for SemverVersion {
fn default() -> Self {
Self {
major: 0,
minor: 0,
patch: 0,
}
.version()
}
}