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