cargo_toml_builder/types/
badges.rs1use std::fmt;
2use std::convert::TryFrom;
3
4use crate::error::Error;
5
6#[derive(Debug, Clone, PartialEq)]
8pub struct Appveyor {
9 pub(crate) repository: String,
10 pub(crate) branch: Option<String>,
11 pub(crate) service: Option<AppveyorService>,
12}
13
14#[derive(Debug, Clone, Copy, PartialEq)]
16pub enum AppveyorService {
17 Github,
19 Bitbucket,
21 Gitlab,
23}
24
25impl fmt::Display for AppveyorService {
26 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
27 use crate::types::badges::AppveyorService::*;
28 write!(f, "{}", match *self {
29 Github => "github",
30 Bitbucket => "bitbucket",
31 Gitlab => "gitlab",
32 })
33 }
34}
35
36impl From<String> for Appveyor {
37 fn from(s: String) -> Appveyor {
38 Appveyor::new(&s)
39 }
40}
41
42impl<'a> From<&'a str> for Appveyor {
43 fn from(s: &'a str) -> Appveyor {
44 Appveyor::new(s)
45 }
46}
47
48impl Appveyor {
49 pub fn new(repository: &str) -> Appveyor {
51 Appveyor {
52 repository: repository.to_string(),
53 branch: None,
54 service: None,
55 }
56 }
57
58 pub fn branch(&mut self, branch: &str) -> &mut Self {
60 self.branch = Some(branch.to_string());
61 self
62 }
63
64 pub fn service(&mut self, service: AppveyorService) -> &mut Self {
66 self.service = Some(service);
67 self
68 }
69
70 pub fn build(&self) -> Self {
72 self.clone()
73 }
74}
75
76#[derive(Debug, Clone, PartialEq)]
78pub struct CircleCi {
79 pub(crate) repository: String,
80 pub(crate) branch: Option<String>,
81}
82
83impl From<String> for CircleCi {
84 fn from(s: String) -> CircleCi {
85 CircleCi::new(&s)
86 }
87}
88
89impl<'a> From<&'a str> for CircleCi {
90 fn from(s: &'a str) -> CircleCi {
91 CircleCi::new(s)
92 }
93}
94
95impl CircleCi {
96 pub fn new(repository: &str) -> CircleCi {
98 CircleCi {
99 repository: repository.to_string(),
100 branch: None,
101 }
102 }
103
104 pub fn branch(&mut self, branch: &str) -> &mut Self {
106 self.branch = Some(branch.to_string());
107 self
108 }
109
110 pub fn build(&self) -> Self {
112 self.clone()
113 }
114}
115
116#[derive(Debug, Clone, PartialEq)]
118pub struct Gitlab {
119 pub(crate) repository: String,
120 pub(crate) branch: Option<String>,
121}
122
123impl From<String> for Gitlab {
124 fn from(s: String) -> Gitlab {
125 Gitlab::new(&s)
126 }
127}
128
129impl<'a> From<&'a str> for Gitlab {
130 fn from(s: &'a str) -> Gitlab {
131 Gitlab::new(s)
132 }
133}
134
135impl Gitlab {
136 pub fn new(repository: &str) -> Gitlab {
138 Gitlab {
139 repository: repository.to_string(),
140 branch: None,
141 }
142 }
143
144 pub fn branch(&mut self, branch: &str) -> &mut Gitlab {
146 self.branch = Some(branch.to_string());
147 self
148 }
149
150 pub fn build(&self) -> Gitlab {
152 self.clone()
153 }
154}
155
156#[derive(Debug, Clone, PartialEq)]
158pub struct TravisCi {
159 pub(crate) repository: String,
160 pub(crate) branch: Option<String>,
161}
162
163impl From<String> for TravisCi {
164 fn from(s: String) -> TravisCi {
165 TravisCi::new(&s)
166 }
167}
168
169impl<'a> From<&'a str> for TravisCi {
170 fn from(s: &'a str) -> TravisCi {
171 TravisCi::new(s)
172 }
173}
174
175impl TravisCi {
176 pub fn new(repository: &str) -> TravisCi {
178 TravisCi {
179 repository: repository.to_string(),
180 branch: None,
181 }
182 }
183
184 pub fn branch(&mut self, branch: &str) -> &mut TravisCi {
186 self.branch = Some(branch.to_string());
187 self
188 }
189
190 pub fn build(&self) -> TravisCi {
192 self.clone()
193 }
194}
195
196#[derive(Debug, Clone, PartialEq)]
198pub struct Codecov {
199 pub(crate) repository: String,
200 pub(crate) branch: Option<String>,
201 pub(crate) service: Option<CodecovService>,
202}
203
204impl From<String> for Codecov {
205 fn from(s: String) -> Codecov {
206 Codecov::new(&s)
207 }
208}
209
210impl<'a> From<&'a str> for Codecov {
211 fn from(s: &'a str) -> Codecov {
212 Codecov::new(s)
213 }
214}
215
216#[derive(Debug, Clone, Copy, PartialEq)]
218pub enum CodecovService {
219 Github,
221 Bitbucket,
223 Gitlab,
225}
226
227impl fmt::Display for CodecovService {
228 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
229 use crate::types::badges::CodecovService::*;
230 write!(f, "{}", match *self {
231 Github => "github",
232 Bitbucket => "bitbucket",
233 Gitlab => "gitlab",
234 })
235 }
236}
237
238impl Codecov {
239 pub fn new(repository: &str) -> Codecov {
241 Codecov {
242 repository: repository.to_string(),
243 branch: None,
244 service: None,
245 }
246 }
247
248 pub fn branch(&mut self, branch: &str) -> &mut Codecov {
250 self.branch = Some(branch.to_string());
251 self
252 }
253
254 pub fn service(&mut self, service: CodecovService) -> &mut Codecov {
256 self.service = Some(service);
257 self
258 }
259
260 pub fn build(&self) -> Codecov {
262 self.clone()
263 }
264}
265
266#[derive(Debug, Clone, PartialEq)]
268pub struct Coveralls {
269 pub(crate) repository: String,
270 pub(crate) branch: Option<String>,
271 pub(crate) service: Option<CoverallsService>,
272}
273
274#[derive(Debug, Clone, Copy, PartialEq)]
276pub enum CoverallsService {
277 Github,
279 Bitbucket,
281 Gitlab,
283}
284
285impl fmt::Display for CoverallsService {
286 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
287 use crate::types::badges::CoverallsService::*;
288 write!(f, "{}", match *self {
289 Github => "github",
290 Bitbucket => "bitbucket",
291 Gitlab => "gitlab",
292 })
293 }
294}
295
296impl From<String> for Coveralls {
297 fn from(s: String) -> Coveralls {
298 Coveralls::new(&s)
299 }
300}
301
302impl<'a> From<&'a str> for Coveralls {
303 fn from(s: &'a str) -> Coveralls {
304 Coveralls::new(s)
305 }
306}
307
308impl Coveralls {
309 pub fn new(repository: &str) -> Coveralls {
311 Coveralls {
312 repository: repository.to_string(),
313 branch: None,
314 service: None,
315 }
316 }
317
318 pub fn branch(&mut self, branch: &str) -> &mut Coveralls {
320 self.branch = Some(branch.to_string());
321 self
322 }
323
324 pub fn service(&mut self, service: CoverallsService) -> &mut Coveralls {
326 self.service = Some(service);
327 self
328 }
329
330 pub fn build(&self) -> Coveralls {
332 self.clone()
333 }
334}
335
336#[derive(Debug, Clone, Copy, PartialEq)]
338pub struct Maintenance {
339 pub(crate) status: MaintenanceStatus,
340}
341
342impl Maintenance {
343 fn new(status: MaintenanceStatus) -> Maintenance {
344 Maintenance { status: status }
345 }
346}
347
348impl TryFrom<String> for Maintenance {
349 type Error = Error;
350 fn try_from(s: String) -> Result<Self, Self::Error> {
351 Ok(Maintenance::new(MaintenanceStatus::try_from(s)?))
352 }
353}
354
355impl<'a> TryFrom<&'a str> for Maintenance {
356 type Error = Error;
357
358 fn try_from(s: &'a str) -> Result<Self, Self::Error> {
359 Ok(Maintenance::new(MaintenanceStatus::try_from(s)?))
360 }
361}
362
363impl From<MaintenanceStatus> for Maintenance {
364 fn from(m: MaintenanceStatus) -> Maintenance {
365 Maintenance {
366 status: m,
367 }
368 }
369}
370
371#[derive(Debug, Clone, Copy, PartialEq)]
373pub enum MaintenanceStatus {
374 Actively,
376 Passively,
378 AsIs,
380 None,
382 Experimental,
384 LookingForMaintainer,
386 Deprecated,
388}
389
390impl TryFrom<String> for MaintenanceStatus {
391 type Error = Error;
392 fn try_from(s: String) -> Result<Self, Self::Error> {
393 TryFrom::try_from(s.as_str())
394 }
395}
396impl<'a> TryFrom<&'a str> for MaintenanceStatus {
397 type Error = Error;
398 fn try_from(s: &'a str) -> Result<Self, Self::Error> {
399 Ok(match s {
400 "actively-developed" => MaintenanceStatus::Actively,
401 "passively-maintained" => MaintenanceStatus::Passively,
402 "as-is" => MaintenanceStatus::AsIs,
403 "none" => MaintenanceStatus::None,
404 "experimental" => MaintenanceStatus::Experimental,
405 "looking-for-maintainer" => MaintenanceStatus::LookingForMaintainer,
406 "deprecated" => MaintenanceStatus::Deprecated,
407 _ => return Err("unrecognized maintenance status string".into()),
408 })
409 }
410}
411
412impl fmt::Display for MaintenanceStatus {
413 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
414 write!(f, "{}", match *self {
415 MaintenanceStatus::Actively => "actively-developed",
416 MaintenanceStatus::Passively => "passively-maintained",
417 MaintenanceStatus::AsIs => "as-is",
418 MaintenanceStatus::None => "none",
419 MaintenanceStatus::Experimental => "experimental",
420 MaintenanceStatus::LookingForMaintainer => "looking-for-maintainer",
421 MaintenanceStatus::Deprecated => "deprecated",
422 })
423 }
424}