rasn_smi/
object_type.rs

1/// A managed Management Information Base (MIB) object.
2pub trait ObjectType
3where
4    Self: TryInto<Self::Syntax>,
5    <Self as TryInto<Self::Syntax>>::Error: rasn::enc::Error + core::fmt::Display,
6{
7    /// The version of SMI syntax that this type uses.
8    type SmiSyntax: SmiSyntax;
9    /// The abstract syntax for the object type. This must resolve to an
10    /// instance of the SMI type.
11    type Syntax: Into<Self::SmiSyntax>;
12    /// Determines the access level of the object.
13    const ACCESS: Access;
14    /// The current status of the object.
15    const STATUS: Status;
16    /// The object identifier for the object.
17    const VALUE: &'static rasn::types::Oid;
18
19    /// Converts `self` into its SMI data type.
20    /// # Errors
21    /// Returns custom `EncodeError` if the conversion fails.
22    fn into_object_syntax(
23        self,
24        codec: rasn::Codec,
25    ) -> Result<Self::SmiSyntax, <Self as TryInto<Self::Syntax>>::Error> {
26        Ok(self
27            .try_into()
28            .map_err(|e| rasn::enc::Error::custom(e, codec))?
29            .into())
30    }
31}
32
33/// A trait representing either a `v1` or `v2` SMI syntax.
34pub trait SmiSyntax {}
35
36impl SmiSyntax for crate::v1::ObjectSyntax {}
37impl SmiSyntax for crate::v2::ObjectSyntax {}
38
39/// The current access provided to the object.
40#[derive(Debug, Clone, Copy, Eq, Ord, PartialEq, PartialOrd)]
41#[non_exhaustive]
42pub enum Access {
43    ReadOnly,
44    WriteOnly,
45    ReadWrite,
46    NotAccessible,
47}
48
49/// The current status of the object's implementation.
50#[derive(Debug, Clone, Copy, Eq, Ord, PartialEq, PartialOrd)]
51#[non_exhaustive]
52pub enum Status {
53    Current,
54    Deprecated,
55    Obsolete,
56}