github_workflow_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    pub version: Option<semver::Version>,
17    pub string: String,
18}
19
20impl Version {
21    pub fn new(s: &str) -> Option<Version> {
22        Some(Version {
23            version: lenient_semver::parse(s).ok(),
24            string: String::from(s),
25        })
26    }
27}
28
29impl fmt::Display for Version {
30    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
31        write!(f, "{}", self.string)
32    }
33}