Skip to main content

tmr_cargo/workspace/
package.rs

1use serde::Serialize;
2
3use crate::ToToml;
4
5#[derive(Serialize)]
6pub struct Authors(Vec<Author>);
7
8impl From<Vec<&str>> for Authors {
9    fn from(authors: Vec<&str>) -> Self {
10        Self(
11            authors
12                .into_iter()
13                .map(|author| Author(author.to_string()))
14                .collect(),
15        )
16    }
17}
18
19impl From<&[&str]> for Authors {
20    fn from(authors: &[&str]) -> Self {
21        Self(
22            authors
23                .iter()
24                .map(|author| Author(author.to_string()))
25                .collect(),
26        )
27    }
28}
29
30impl ToToml for Authors {}
31
32#[derive(Serialize)]
33pub struct Author(String);
34
35impl ToToml for Author {}
36
37#[derive(Serialize)]
38pub struct Categories(Vec<Category>);
39
40impl From<Vec<&str>> for Categories {
41    fn from(categories: Vec<&str>) -> Self {
42        Self(
43            categories
44                .into_iter()
45                .map(|category| Category(category.to_string()))
46                .collect(),
47        )
48    }
49}
50
51impl From<&[&str]> for Categories {
52    fn from(categories: &[&str]) -> Self {
53        Self(
54            categories
55                .iter()
56                .map(|category| Category(category.to_string()))
57                .collect(),
58        )
59    }
60}
61
62impl ToToml for Categories {}
63
64#[derive(Serialize)]
65pub struct Category(String);
66
67impl ToToml for Category {}
68
69#[derive(Serialize)]
70pub struct Description(String);
71
72impl From<String> for Description {
73    fn from(description: String) -> Self {
74        Self(description)
75    }
76}
77
78impl From<&str> for Description {
79    fn from(description: &str) -> Self {
80        Self(description.to_string())
81    }
82}
83
84impl ToToml for Description {}
85
86#[derive(Serialize)]
87pub struct Documentation(String);
88
89impl From<&str> for Documentation {
90    fn from(documentation: &str) -> Self {
91        Self(documentation.to_string())
92    }
93}
94
95impl From<String> for Documentation {
96    fn from(documentation: String) -> Self {
97        Self(documentation)
98    }
99}
100
101impl ToToml for Documentation {}
102
103#[derive(Serialize)]
104pub enum Edition {
105    #[serde(rename = "2015")]
106    Edition2015,
107    #[serde(rename = "2018")]
108    Edition2018,
109    #[serde(rename = "2021")]
110    Edition2021,
111}
112
113impl ToToml for Edition {}
114
115#[derive(Serialize)]
116pub struct Homepage(String);
117
118impl From<&str> for Homepage {
119    fn from(homepage: &str) -> Self {
120        Self(homepage.to_string())
121    }
122}
123
124impl From<String> for Homepage {
125    fn from(homepage: String) -> Self {
126        Self(homepage)
127    }
128}
129
130impl ToToml for Homepage {}
131
132#[derive(Serialize)]
133pub struct Keywords(Vec<Keyword>);
134
135impl From<Vec<&str>> for Keywords {
136    fn from(keywords: Vec<&str>) -> Self {
137        Self(
138            keywords
139                .into_iter()
140                .map(|keyword| Keyword(keyword.to_string()))
141                .collect(),
142        )
143    }
144}
145
146impl From<&[&str]> for Keywords {
147    fn from(keywords: &[&str]) -> Self {
148        Self(
149            keywords
150                .iter()
151                .map(|keyword| Keyword(keyword.to_string()))
152                .collect(),
153        )
154    }
155}
156
157impl ToToml for Keywords {}
158
159#[derive(Serialize)]
160pub struct Keyword(String);
161
162impl ToToml for Keyword {}
163
164#[derive(Serialize)]
165pub struct License(String);
166
167impl From<&str> for License {
168    fn from(license: &str) -> Self {
169        Self(license.to_string())
170    }
171}
172
173impl ToToml for License {}
174
175#[derive(Serialize)]
176pub struct Publish(bool);
177
178impl From<bool> for Publish {
179    fn from(publish: bool) -> Self {
180        Self(publish)
181    }
182}
183
184impl ToToml for Publish {}
185
186#[derive(Serialize)]
187pub struct Readme(String);
188
189impl From<&str> for Readme {
190    fn from(readme: &str) -> Self {
191        Self(readme.to_string())
192    }
193}
194
195impl ToToml for Readme {}
196
197#[derive(Serialize)]
198pub struct Repository(String);
199
200impl From<&str> for Repository {
201    fn from(repository: &str) -> Self {
202        Self(repository.to_string())
203    }
204}
205
206impl From<String> for Repository {
207    fn from(repository: String) -> Self {
208        Self(repository)
209    }
210}
211
212impl ToToml for Repository {}
213
214pub struct RustVersion(semver::Version);
215
216impl Serialize for RustVersion {
217    fn serialize<S: serde::Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
218        self.0.to_string().serialize(serializer)
219    }
220}
221
222impl TryFrom<&str> for RustVersion {
223    type Error = semver::Error;
224
225    fn try_from(rust_version: &str) -> Result<Self, Self::Error> {
226        Ok(Self(semver::Version::parse(rust_version)?))
227    }
228}
229
230impl From<semver::Version> for RustVersion {
231    fn from(rust_version: semver::Version) -> Self {
232        Self(rust_version)
233    }
234}
235
236impl ToToml for RustVersion {}
237
238pub struct Version(semver::Version);
239
240impl Serialize for Version {
241    fn serialize<S: serde::Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
242        self.0.to_string().serialize(serializer)
243    }
244}
245
246impl TryFrom<&str> for Version {
247    type Error = semver::Error;
248
249    fn try_from(version: &str) -> Result<Self, Self::Error> {
250        Ok(Self(semver::Version::parse(version)?))
251    }
252}
253
254impl TryFrom<String> for Version {
255    type Error = semver::Error;
256
257    fn try_from(version: String) -> Result<Self, Self::Error> {
258        Ok(Self(semver::Version::parse(&version)?))
259    }
260}
261
262impl ToToml for Version {}