cargo_utils/
dependency.rs1#[derive(PartialEq, Eq, Hash, Ord, PartialOrd, Clone, Debug, Copy)]
2pub enum DepKind {
3 Normal,
4 Development,
5 Build,
6}
7
8#[derive(Clone, Debug, PartialEq, Eq)]
10pub struct DepTable {
11 kind: DepKind,
12 target: Option<String>,
13}
14
15impl DepTable {
16 pub const KINDS: &'static [Self] = &[
17 Self::new().set_kind(DepKind::Normal),
18 Self::new().set_kind(DepKind::Development),
19 Self::new().set_kind(DepKind::Build),
20 ];
21
22 pub(crate) const fn new() -> Self {
24 Self {
25 kind: DepKind::Normal,
26 target: None,
27 }
28 }
29
30 pub(crate) const fn set_kind(mut self, kind: DepKind) -> Self {
32 self.kind = kind;
33 self
34 }
35
36 pub(crate) fn set_target(mut self, target: impl Into<String>) -> Self {
38 self.target = Some(target.into());
39 self
40 }
41
42 pub(crate) fn kind_table(&self) -> &str {
43 match self.kind {
44 DepKind::Normal => "dependencies",
45 DepKind::Development => "dev-dependencies",
46 DepKind::Build => "build-dependencies",
47 }
48 }
49}
50
51impl Default for DepTable {
52 fn default() -> Self {
53 Self::new()
54 }
55}
56
57impl From<DepKind> for DepTable {
58 fn from(other: DepKind) -> Self {
59 Self::new().set_kind(other)
60 }
61}