Skip to main content

tmr_cargo/
workspace.rs

1use serde::Serialize;
2
3use crate::ToToml;
4
5pub mod package;
6
7#[derive(Serialize)]
8pub struct Members(Vec<Member>);
9
10impl From<Vec<&str>> for Members {
11    fn from(members: Vec<&str>) -> Self {
12        Self(
13            members
14                .into_iter()
15                .map(|member| Member(member.to_string()))
16                .collect(),
17        )
18    }
19}
20
21impl From<&[&str]> for Members {
22    fn from(members: &[&str]) -> Self {
23        Self(
24            members
25                .iter()
26                .map(|member| Member(member.to_string()))
27                .collect(),
28        )
29    }
30}
31
32impl ToToml for Members {}
33
34#[derive(Serialize)]
35pub struct Member(String);
36
37impl ToToml for Member {}
38
39#[derive(Serialize)]
40pub struct Excludes(Vec<Exclude>);
41
42impl From<Vec<&str>> for Excludes {
43    fn from(excludes: Vec<&str>) -> Self {
44        Self(
45            excludes
46                .into_iter()
47                .map(|exclude| Exclude(exclude.to_string()))
48                .collect(),
49        )
50    }
51}
52
53impl From<&[&str]> for Excludes {
54    fn from(excludes: &[&str]) -> Self {
55        Self(
56            excludes
57                .iter()
58                .map(|exclude| Exclude(exclude.to_string()))
59                .collect(),
60        )
61    }
62}
63
64impl ToToml for Excludes {}
65
66#[derive(Serialize)]
67pub struct Exclude(String);
68
69impl ToToml for Exclude {}
70
71pub enum Resolver {
72    V1,
73    V2,
74}
75
76impl Serialize for Resolver {
77    fn serialize<S: serde::Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
78        match self {
79            Resolver::V1 => "1".serialize(serializer),
80            Resolver::V2 => "2".serialize(serializer),
81        }
82    }
83}
84
85impl TryFrom<&str> for Resolver {
86    type Error = ();
87
88    fn try_from(resolver: &str) -> Result<Self, Self::Error> {
89        match resolver {
90            "1" => Ok(Self::V1),
91            "2" => Ok(Self::V2),
92            _ => Err(()),
93        }
94    }
95}
96
97impl ToToml for Resolver {}