32 lines
696 B
Rust
32 lines
696 B
Rust
//! # SemVer
|
|
|
|
//! A simple Semantic Versioning struct to handle comparisons and ordering
|
|
|
|
// Uses
|
|
use std::fmt;
|
|
|
|
#[derive(Clone, Ord, PartialOrd, Eq, PartialEq, Debug)]
|
|
pub struct SemVer {
|
|
pub major: i32,
|
|
pub minor: i32,
|
|
pub patch: i32,
|
|
}
|
|
|
|
impl fmt::Display for SemVer {
|
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
|
write!(f, "{}.{}.{}", self.major, self.minor, self.patch)
|
|
}
|
|
}
|
|
|
|
impl From<&str> for SemVer {
|
|
fn from(s: &str) -> SemVer {
|
|
let v: Vec<&str> = s.split('.').collect();
|
|
|
|
SemVer {
|
|
major: v[0].parse().unwrap(),
|
|
minor: v[1].parse().unwrap(),
|
|
patch: v[2].parse().unwrap(),
|
|
}
|
|
}
|
|
}
|