guppy/
dependency_kind.rs

1// Copyright (c) The cargo-guppy Contributors
2// SPDX-License-Identifier: MIT OR Apache-2.0
3
4use std::fmt;
5
6/// A descriptor for the kind of dependency.
7///
8/// Cargo dependencies may be one of three kinds.
9#[derive(Copy, Clone, Debug, Eq, Hash, PartialEq)]
10pub enum DependencyKind {
11    /// Normal dependencies.
12    ///
13    /// These are specified in the `[dependencies]` section.
14    Normal,
15
16    /// Dependencies used for development only.
17    ///
18    /// These are specified in the `[dev-dependencies]` section, and are used for tests,
19    /// benchmarks and similar.
20    Development,
21
22    /// Dependencies used for build scripts.
23    ///
24    /// These are specified in the `[build-dependencies]` section.
25    Build,
26}
27
28impl DependencyKind {
29    /// A list of all the possible values of `DependencyKind`.
30    pub const VALUES: &'static [Self; 3] = &[
31        DependencyKind::Normal,
32        DependencyKind::Development,
33        DependencyKind::Build,
34    ];
35
36    /// Returns a string representing the kind of dependency this is.
37    pub fn to_str(self) -> &'static str {
38        match self {
39            DependencyKind::Normal => "normal",
40            DependencyKind::Development => "dev",
41            DependencyKind::Build => "build",
42        }
43    }
44}
45
46impl fmt::Display for DependencyKind {
47    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
48        write!(f, "{}", self.to_str())
49    }
50}