pedant_core/resolution/rust/
version.rs1use std::fmt;
4use std::sync::Arc;
5
6#[derive(Debug, Clone, PartialEq, Eq)]
11pub struct CargoPackageVersion {
12 text: Arc<str>,
13}
14
15impl CargoPackageVersion {
16 pub(super) fn parse(text: &str) -> Result<Self, semver::Error> {
18 semver::Version::parse(text)?;
19 Ok(Self {
20 text: Arc::from(text),
21 })
22 }
23
24 pub fn as_str(&self) -> &str {
26 &self.text
27 }
28}
29
30impl fmt::Display for CargoPackageVersion {
31 fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
32 formatter.write_str(&self.text)
33 }
34}