alpm_types/package/
installation.rs

1//! Package installation handling.
2
3/// Represents the reason why a package was installed.
4///
5/// # Examples
6///
7/// Parsing from strings:
8///
9/// ```
10/// use std::str::FromStr;
11///
12/// use alpm_types::PackageInstallReason;
13///
14/// # fn main() -> Result<(), alpm_types::Error> {
15/// assert_eq!(
16///     PackageInstallReason::from_str("0")?,
17///     PackageInstallReason::Explicit
18/// );
19/// assert_eq!(
20///     PackageInstallReason::from_str("1")?,
21///     PackageInstallReason::Depend
22/// );
23///
24/// // Invalid values return an error.
25/// assert!(PackageInstallReason::from_str("2").is_err());
26/// # Ok(())
27/// # }
28/// ```
29///
30/// Displaying and serializing:
31///
32/// ```
33/// use alpm_types::PackageInstallReason;
34///
35/// # fn main() -> Result<(), alpm_types::Error> {
36/// assert_eq!(PackageInstallReason::Explicit.to_string(), "0");
37/// assert_eq!(
38///     serde_json::to_string(&PackageInstallReason::Depend).expect("Serialization failed"),
39///     "\"Depend\""
40/// );
41/// # Ok(())
42/// # }
43/// ```
44#[derive(
45    Clone,
46    Copy,
47    Debug,
48    Default,
49    PartialEq,
50    Eq,
51    serde::Deserialize,
52    serde::Serialize,
53    strum::EnumString,
54    strum::Display,
55    strum::AsRefStr,
56)]
57#[repr(u8)]
58pub enum PackageInstallReason {
59    /// Explicitly requested by the user.
60    #[default]
61    #[strum(to_string = "0")]
62    Explicit = 0,
63    /// Installed as a dependency for another package.
64    #[strum(to_string = "1")]
65    Depend = 1,
66}