2022-12-03 12:15:03 -06:00
|
|
|
// ! A unified versioning system for Rust.
|
|
|
|
#![no_std]
|
|
|
|
use core::{fmt::Display, prelude::rust_2021::derive};
|
|
|
|
use serde::{Deserialize, Serialize};
|
|
|
|
|
2022-12-05 00:29:21 -06:00
|
|
|
pub const VERSION: Version = Version::new(0, 1, 3);
|
|
|
|
|
2022-12-03 12:15:03 -06:00
|
|
|
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Serialize, Deserialize)]
|
|
|
|
pub struct Version {
|
|
|
|
pub major: u8,
|
|
|
|
pub minor: u8,
|
|
|
|
pub patch: u8,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Version {
|
2022-12-05 00:29:21 -06:00
|
|
|
pub const fn new(major: u8, minor: u8, patch: u8) -> Self {
|
2022-12-03 12:15:03 -06:00
|
|
|
Self {
|
|
|
|
major,
|
|
|
|
minor,
|
|
|
|
patch,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn new_from_env(vstring: &'static str) -> Self {
|
|
|
|
let mut spl = vstring.split(".");
|
|
|
|
if spl.clone().count() > 3 {
|
|
|
|
panic!("Improper version string");
|
|
|
|
}
|
|
|
|
// TODO: handle failing any of these
|
|
|
|
let major: u8 = spl.nth(0).unwrap().parse().unwrap();
|
|
|
|
let minor: u8 = spl.nth(1).unwrap().parse().unwrap();
|
|
|
|
let patch: u8 = spl.nth(2).unwrap().parse().unwrap();
|
|
|
|
|
|
|
|
Self {
|
|
|
|
major,
|
|
|
|
minor,
|
|
|
|
patch,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Display for Version {
|
|
|
|
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
|
2022-12-05 04:14:26 -06:00
|
|
|
write!(f, "{}.{}.{}", self.major, self.minor, self.patch)?;
|
2022-12-03 12:15:03 -06:00
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
}
|