Skip to main content

tmr_cargo/
package.rs

1use serde::Serialize;
2
3use crate::ToToml;
4
5#[derive(Serialize)]
6pub struct Name(String);
7
8impl From<&str> for Name {
9    fn from(name: &str) -> Self {
10        Self(name.to_string())
11    }
12}
13
14impl Into<String> for &Name {
15    fn into(self) -> String {
16        self.0.to_string()
17    }
18}
19
20impl ToToml for Name {}
21
22pub struct Version(semver::Version);
23
24impl Serialize for Version {
25    fn serialize<S: serde::Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
26        self.0.to_string().serialize(serializer)
27    }
28}
29
30impl ToToml for Version {}
31
32impl TryFrom<&str> for Version {
33    type Error = semver::Error;
34
35    fn try_from(version: &str) -> Result<Self, Self::Error> {
36        Ok(Self(semver::Version::parse(version)?))
37    }
38}
39
40#[derive(Serialize)]
41pub struct Description(String);
42
43impl From<String> for Description {
44    fn from(description: String) -> Self {
45        Self(description)
46    }
47}
48
49impl Into<String> for Description {
50    fn into(self) -> String {
51        self.0
52    }
53}
54
55impl ToToml for Description {}