1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
use std::fmt;
use camino::Utf8PathBuf;
#[cfg(feature = "builder")]
use derive_builder::Builder;
use semver::VersionReq;
use serde::{Deserialize, Deserializer, Serialize};
#[derive(Eq, PartialEq, Clone, Debug, Copy, Hash, Serialize, Deserialize)]
pub enum DependencyKind {
#[serde(rename = "normal")]
Normal,
#[serde(rename = "dev")]
Development,
#[serde(rename = "build")]
Build,
#[doc(hidden)]
#[serde(other)]
Unknown,
}
impl Default for DependencyKind {
fn default() -> DependencyKind {
DependencyKind::Normal
}
}
impl fmt::Display for DependencyKind {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
let s = serde_json::to_string(self).unwrap();
f.write_str(&s[1..s.len() - 1])
}
}
pub(super) fn parse_dependency_kind<'de, D>(d: D) -> Result<DependencyKind, D::Error>
where
D: Deserializer<'de>,
{
Deserialize::deserialize(d).map(|x: Option<_>| x.unwrap_or_default())
}
#[derive(Clone, Serialize, Deserialize, Debug)]
#[cfg_attr(feature = "builder", derive(Builder))]
#[non_exhaustive]
#[cfg_attr(feature = "builder", builder(pattern = "owned", setter(into)))]
pub struct Dependency {
pub name: String,
pub source: Option<String>,
pub req: VersionReq,
#[serde(deserialize_with = "parse_dependency_kind")]
pub kind: DependencyKind,
pub optional: bool,
pub uses_default_features: bool,
pub features: Vec<String>,
pub target: Option<Platform>,
pub rename: Option<String>,
pub registry: Option<String>,
pub path: Option<Utf8PathBuf>,
}
pub use cargo_platform::Platform;