async_snmp/
version.rs

1//! SNMP version enumeration.
2
3/// SNMP protocol version.
4#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
5#[non_exhaustive]
6#[derive(Default)]
7pub enum Version {
8    /// SNMPv1 (RFC 1157)
9    V1,
10    /// SNMPv2c (RFC 1901)
11    #[default]
12    V2c,
13    /// SNMPv3 (RFC 3411-3418)
14    V3,
15}
16
17impl Version {
18    /// Get the BER-encoded version number.
19    pub const fn as_i32(self) -> i32 {
20        match self {
21            Version::V1 => 0,
22            Version::V2c => 1,
23            Version::V3 => 3,
24        }
25    }
26
27    /// Create from BER-encoded version number.
28    pub const fn from_i32(value: i32) -> Option<Self> {
29        match value {
30            0 => Some(Version::V1),
31            1 => Some(Version::V2c),
32            3 => Some(Version::V3),
33            _ => None,
34        }
35    }
36}
37
38impl std::fmt::Display for Version {
39    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
40        match self {
41            Version::V1 => write!(f, "SNMPv1"),
42            Version::V2c => write!(f, "SNMPv2c"),
43            Version::V3 => write!(f, "SNMPv3"),
44        }
45    }
46}