pub enum GetResult {
Value(Value),
NoSuchObject,
NoSuchInstance,
}Expand description
Result of a GET operation on a specific OID (RFC 3416).
This enum distinguishes between the RFC 3416-mandated exception types:
Value: The OID exists and has the given valueNoSuchObject: The OID’s object type is not supported (agent doesn’t implement this MIB)NoSuchInstance: The object type exists but this specific instance doesn’t (e.g., table row doesn’t exist)
§Version Differences
- SNMPv1: Both exception types result in a
noSuchNameerror response - SNMPv2c/v3: Returns the appropriate exception value in the response varbind
§Choosing NoSuchObject vs NoSuchInstance
| Situation | Variant |
|---|---|
| OID prefix not recognized | NoSuchObject |
| Scalar object not implemented | NoSuchObject |
| Table column not implemented | NoSuchObject |
| Table row doesn’t exist | NoSuchInstance |
| Scalar has no value (optional) | NoSuchInstance |
§Example: Scalar Objects
use async_snmp::handler::GetResult;
use async_snmp::{Value, oid};
fn get_scalar(oid: &async_snmp::Oid) -> GetResult {
if oid == &oid!(1, 3, 6, 1, 2, 1, 1, 1, 0) { // sysDescr.0
GetResult::Value(Value::OctetString("My SNMP Agent".into()))
} else if oid == &oid!(1, 3, 6, 1, 2, 1, 1, 2, 0) { // sysObjectID.0
GetResult::Value(Value::ObjectIdentifier(oid!(1, 3, 6, 1, 4, 1, 99999)))
} else {
GetResult::NoSuchObject
}
}§Example: Table Objects
use async_snmp::handler::GetResult;
use async_snmp::{Value, Oid, oid};
struct IfTable {
entries: Vec<(u32, String)>, // (index, description)
}
impl IfTable {
fn get(&self, oid: &Oid) -> GetResult {
let if_descr_prefix = oid!(1, 3, 6, 1, 2, 1, 2, 2, 1, 2);
if !oid.starts_with(&if_descr_prefix) {
return GetResult::NoSuchObject; // Not our column
}
// Extract index from OID (position after prefix)
let arcs = oid.arcs();
if arcs.len() != if_descr_prefix.len() + 1 {
return GetResult::NoSuchInstance; // Wrong index format
}
let index = arcs[if_descr_prefix.len()];
match self.entries.iter().find(|(i, _)| *i == index) {
Some((_, desc)) => GetResult::Value(Value::OctetString(desc.clone().into())),
None => GetResult::NoSuchInstance, // Row doesn't exist
}
}
}Variants§
Value(Value)
The OID exists and has this value.
NoSuchObject
The object type is not implemented by this agent.
Use this when the OID prefix (object type) is not recognized. This typically means the handler doesn’t implement this part of the MIB.
NoSuchInstance
The object type exists but this specific instance doesn’t.
Use this when the OID prefix is valid but the instance identifier (e.g., table index) doesn’t exist. This is common for table objects where the row has been deleted or never existed.
Implementations§
Trait Implementations§
impl StructuralPartialEq for GetResult
Auto Trait Implementations§
impl !Freeze for GetResult
impl RefUnwindSafe for GetResult
impl Send for GetResult
impl Sync for GetResult
impl Unpin for GetResult
impl UnwindSafe for GetResult
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more