system_update_committer/metadata/
configuration_without_recovery.rs1use fidl_fuchsia_paver as paver;
6
7#[derive(Debug, Clone, PartialEq)]
10pub enum ConfigurationWithoutRecovery {
11 A,
12 B,
13}
14
15impl From<&ConfigurationWithoutRecovery> for paver::Configuration {
16 fn from(config: &ConfigurationWithoutRecovery) -> Self {
17 match *config {
18 ConfigurationWithoutRecovery::A => Self::A,
19 ConfigurationWithoutRecovery::B => Self::B,
20 }
21 }
22}
23
24impl ConfigurationWithoutRecovery {
25 pub fn to_alternate(&self) -> &Self {
26 match *self {
27 Self::A => &Self::B,
28 Self::B => &Self::A,
29 }
30 }
31}
32
33#[cfg(test)]
34impl TryFrom<&paver::Configuration> for ConfigurationWithoutRecovery {
35 type Error = ();
36 fn try_from(config: &paver::Configuration) -> Result<Self, Self::Error> {
37 match *config {
38 paver::Configuration::A => Ok(Self::A),
39 paver::Configuration::B => Ok(Self::B),
40 _ => Err(()),
41 }
42 }
43}
44
45#[cfg(test)]
46mod tests {
47 use super::*;
48
49 #[test]
50 fn to_alternate() {
51 assert_eq!(
52 ConfigurationWithoutRecovery::A.to_alternate(),
53 &ConfigurationWithoutRecovery::B
54 );
55 assert_eq!(
56 ConfigurationWithoutRecovery::B.to_alternate(),
57 &ConfigurationWithoutRecovery::A
58 );
59 }
60
61 #[test]
62 fn fidl_conversion() {
63 assert_eq!(
64 paver::Configuration::from(&ConfigurationWithoutRecovery::A),
65 paver::Configuration::A
66 );
67 assert_eq!(
68 paver::Configuration::from(&ConfigurationWithoutRecovery::B),
69 paver::Configuration::B
70 );
71 }
72}