github_workflows_update/
version.rs

1// Copyright (C) 2022 Leandro Lisboa Penz <lpenz@lpenz.org>
2// This file is subject to the terms and conditions defined in
3// file 'LICENSE', which is part of this source code package.
4
5//! Type wrapper for versions; currently using [`semver`]
6//! with [`lenient_semver`]
7
8use std::fmt;
9
10use lenient_semver;
11use semver;
12
13/// Wrapper for the underlying external Version type
14#[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Clone, Default, Hash)]
15pub struct Version {
16    /// The parsed, full-typed version
17    pub version: Option<semver::Version>,
18    /// The original parsed string
19    pub string: String,
20}
21
22impl Version {
23    pub fn new(s: &str) -> Option<Version> {
24        Some(Version {
25            version: lenient_semver::parse(s).ok(),
26            string: String::from(s),
27        })
28    }
29}
30
31impl fmt::Display for Version {
32    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
33        write!(f, "{}", self.string)
34    }
35}