1 //! Version part module. 2 //! 3 //! A module that provides the `VersionPart` enum, with the specification of all available version 4 //! parts. Each version string is broken down into these version parts when being parsed to a 5 //! `Version`. 6 7 use std::fmt; 8 9 /// Enum of version string parts. 10 /// 11 /// Each version string is broken down into these version parts when being parsed to a `Version`. 12 #[derive(Debug, PartialEq)] 13 pub enum VersionPart<'a> { 14 /// Numeric part, most common in version strings. 15 /// Holds the numerical value. 16 Number(i32), 17 18 /// A text part. 19 /// These parts usually hold text with an yet unknown definition. 20 /// Holds the string slice. 21 Text(&'a str), 22 } 23 24 impl<'a> fmt::Display for VersionPart<'a> { fmt(&self, f: &mut fmt::Formatter) -> fmt::Result25 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { 26 match self { 27 VersionPart::Number(n) => write!(f, "{}", n), 28 VersionPart::Text(t) => write!(f, "{}", t), 29 } 30 } 31 } 32 33 #[cfg_attr(tarpaulin, skip)] 34 #[cfg(test)] 35 mod tests { 36 use crate::version_part::VersionPart; 37 38 #[test] display()39 fn display() { 40 assert_eq!(format!("{}", VersionPart::Number(123)), "123"); 41 assert_eq!(format!("{}", VersionPart::Text("123")), "123"); 42 } 43 } 44