pub enum SetResult {
Show 13 variants
Ok,
NoAccess,
NotWritable,
WrongType,
WrongLength,
WrongEncoding,
WrongValue,
NoCreation,
InconsistentValue,
ResourceUnavailable,
CommitFailed,
UndoFailed,
InconsistentName,
}Expand description
Result of a SET operation phase (RFC 3416).
This enum is used by the two-phase SET protocol:
MibHandler::test_set: ReturnsOkif the SET would succeedMibHandler::commit_set: ReturnsOkif the change was appliedMibHandler::undo_set: Does not returnSetResult(best-effort)
§Choosing the Right Error
| Situation | Variant |
|---|---|
| SET succeeded | Ok |
| User lacks permission | NoAccess |
| Object is read-only by design | NotWritable |
| Wrong ASN.1 type (e.g., String for Integer) | WrongType |
| Value too long/short | WrongLength |
| Value encoding error | WrongEncoding |
| Semantic validation failed | WrongValue |
| Cannot create table row | NoCreation |
| Values conflict within request | InconsistentValue |
| Out of memory, lock contention | ResourceUnavailable |
§Example
use async_snmp::handler::SetResult;
use async_snmp::Value;
fn validate_admin_status(value: &Value) -> SetResult {
match value {
Value::Integer(v) if *v == 1 || *v == 2 => SetResult::Ok, // up(1) or down(2)
Value::Integer(_) => SetResult::WrongValue, // Invalid admin status
_ => SetResult::WrongType, // Must be Integer
}
}
assert_eq!(validate_admin_status(&Value::Integer(1)), SetResult::Ok);
assert_eq!(validate_admin_status(&Value::Integer(99)), SetResult::WrongValue);
assert_eq!(validate_admin_status(&Value::OctetString("up".into())), SetResult::WrongType);Variants§
Ok
Operation succeeded.
NoAccess
Access denied (security/authorization failure).
Use this when the request lacks sufficient access rights to modify the object, based on the security context (user, community, etc.). Maps to RFC 3416 error status code 6 (noAccess).
NotWritable
Object is inherently read-only (not writable by design).
Use this when the object cannot be modified regardless of who is making the request. Maps to RFC 3416 error status code 17 (notWritable).
WrongType
Value has wrong ASN.1 type for this OID.
Use when the provided value type doesn’t match the expected type (e.g., OctetString provided for an Integer object).
WrongLength
Value has wrong length for this OID.
Use when the value length violates constraints (e.g., DisplayString longer than 255 characters).
WrongEncoding
Value encoding is incorrect.
WrongValue
Value is not valid for this OID (semantic check failed).
Use when the value type is correct but the value itself is invalid (e.g., negative value for an unsigned counter, or value outside an enumeration’s valid range).
NoCreation
Cannot create new row (table doesn’t support row creation).
InconsistentValue
Value is inconsistent with other values in the same SET.
Resource unavailable (memory, locks, etc.).
CommitFailed
Commit failed (internal error during apply).
UndoFailed
Undo failed (internal error during rollback).
InconsistentName
Row name is inconsistent with existing data.
Implementations§
Source§impl SetResult
impl SetResult
Sourcepub fn to_error_status(&self) -> ErrorStatus
pub fn to_error_status(&self) -> ErrorStatus
Convert to an ErrorStatus code.