1 //! This module contains `Dependency` and the types/functions it uses for deserialization.
3 use semver
::VersionReq
;
4 use serde
::{Deserialize, Deserializer, Serialize}
;
7 #[derive(PartialEq, Clone, Debug, Copy, Serialize, Deserialize)]
8 /// Dependencies can come in three kinds
9 pub enum DependencyKind
{
10 #[serde(rename = "normal")]
13 #[serde(rename = "dev")]
14 /// Those used in tests only
16 #[serde(rename = "build")]
17 /// Those used in build scripts only
24 impl Default
for DependencyKind
{
25 fn default() -> DependencyKind
{
26 DependencyKind
::Normal
30 /// The `kind` can be `null`, which is interpreted as the default - `Normal`.
31 pub(super) fn parse_dependency_kind
<'de
, D
>(d
: D
) -> Result
<DependencyKind
, D
::Error
>
35 Deserialize
::deserialize(d
).map(|x
: Option
<_
>| x
.unwrap_or_default())
38 #[derive(Clone, Serialize, Deserialize, Debug)]
39 /// A dependency of the main crate
40 pub struct Dependency
{
41 /// Name as given in the `Cargo.toml`
43 /// The source of dependency
44 pub source
: Option
<String
>,
45 /// The required version
47 /// The kind of dependency this is
48 #[serde(deserialize_with = "parse_dependency_kind")]
49 pub kind
: DependencyKind
,
50 /// Whether this dependency is required or optional
52 /// Whether the default features in this dependency are used.
53 pub uses_default_features
: bool
,
54 /// The list of features enabled for this dependency.
55 pub features
: Vec
<String
>,
56 /// The target this dependency is specific to.
58 /// Use the [`Display`] trait to access the contents.
60 /// [`Display`]: https://doc.rust-lang.org/std/fmt/trait.Display.html
61 pub target
: Option
<Platform
>,
62 /// If the dependency is renamed, this is the new name for the dependency
63 /// as a string. None if it is not renamed.
64 pub rename
: Option
<String
>,
65 /// The URL of the index of the registry where this dependency is from.
67 /// If None, the dependency is from crates.io.
68 pub registry
: Option
<String
>,
71 __do_not_match_exhaustively
: (),
74 /// A target platform.
75 #[derive(Clone, Serialize, Deserialize, Debug)]
78 /// The underlying string representation of a platform.
82 impl fmt
::Display
for Platform
{
83 fn fmt(&self, f
: &mut fmt
::Formatter
<'_
>) -> fmt
::Result
{
84 fmt
::Display
::fmt(&self.repr
, f
)