]> git.proxmox.com Git - rustc.git/blame - vendor/cargo_metadata/src/dependency.rs
New upstream version 1.46.0~beta.2+dfsg1
[rustc.git] / vendor / cargo_metadata / src / dependency.rs
CommitLineData
ba9703b0
XL
1//! This module contains `Dependency` and the types/functions it uses for deserialization.
2
3use semver::VersionReq;
4use serde::{Deserialize, Deserializer};
5use std::fmt;
6
7#[derive(PartialEq, Clone, Debug, Copy, Serialize, Deserialize)]
8/// Dependencies can come in three kinds
9pub enum DependencyKind {
10 #[serde(rename = "normal")]
11 /// The 'normal' kind
12 Normal,
13 #[serde(rename = "dev")]
14 /// Those used in tests only
15 Development,
16 #[serde(rename = "build")]
17 /// Those used in build scripts only
18 Build,
19 #[doc(hidden)]
20 #[serde(other)]
21 Unknown,
22}
23
24impl Default for DependencyKind {
25 fn default() -> DependencyKind {
26 DependencyKind::Normal
27 }
28}
29
30/// The `kind` can be `null`, which is interpreted as the default - `Normal`.
31pub(super) fn parse_dependency_kind<'de, D>(d: D) -> Result<DependencyKind, D::Error>
32where
33 D: Deserializer<'de>,
34{
35 Deserialize::deserialize(d).map(|x: Option<_>| x.unwrap_or_default())
36}
37
38#[derive(Clone, Serialize, Deserialize, Debug)]
39/// A dependency of the main crate
40pub struct Dependency {
41 /// Name as given in the `Cargo.toml`
42 pub name: String,
43 /// The source of dependency
44 pub source: Option<String>,
45 /// The required version
46 pub req: VersionReq,
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
51 pub optional: bool,
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.
57 ///
58 /// Use the [`Display`] trait to access the contents.
59 ///
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.
66 ///
67 /// If None, the dependency is from crates.io.
68 pub registry: Option<String>,
69 #[doc(hidden)]
70 #[serde(skip)]
71 __do_not_match_exhaustively: (),
72}
73
74/// A target platform.
75#[derive(Clone, Serialize, Deserialize, Debug)]
76#[serde(transparent)]
f035d41b
XL
77pub struct Platform {
78 /// The underlying string representation of a platform.
79 pub repr: String,
80}
ba9703b0
XL
81
82impl fmt::Display for Platform {
83 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f035d41b 84 fmt::Display::fmt(&self.repr, f)
ba9703b0
XL
85 }
86}