pub enum GetResult {
Value(Value),
NoSuchObject,
NoSuchInstance,
}Expand description
Result of a GET operation on a specific OID.
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)
For SNMPv1, both exception types result in a noSuchName error response.
For SNMPv2c/v3, they result in the appropriate exception value in the response.
§Example
use async_snmp::handler::{MibHandler, RequestContext, GetResult, GetNextResult, BoxFuture};
use async_snmp::{Oid, Value, VarBind, oid};
struct IfTableHandler {
// Simulates interface table with indices 1 and 2
interfaces: Vec<u32>,
}
impl MibHandler for IfTableHandler {
fn get<'a>(&'a self, _ctx: &'a RequestContext, oid: &'a Oid) -> BoxFuture<'a, GetResult> {
Box::pin(async move {
let if_descr_prefix = oid!(1, 3, 6, 1, 2, 1, 2, 2, 1, 2);
if oid.starts_with(&if_descr_prefix) {
// Extract index from OID
if let Some(&index) = oid.arcs().get(if_descr_prefix.len()) {
if self.interfaces.contains(&index) {
return GetResult::Value(Value::OctetString(
format!("eth{}", index - 1).into()
));
}
// Index exists in MIB but not in our table
return GetResult::NoSuchInstance;
}
}
// OID is not in our MIB at all
GetResult::NoSuchObject
})
}
fn get_next<'a>(&'a self, _ctx: &'a RequestContext, _oid: &'a Oid) -> BoxFuture<'a, GetNextResult> {
Box::pin(async move { GetNextResult::EndOfMibView }) // Simplified
}
}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.
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.
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