Value

Enum Value 

Source
#[non_exhaustive]
pub enum Value {
Show 14 variants Integer(i32), OctetString(Bytes), Null, ObjectIdentifier(Oid), IpAddress([u8; 4]), Counter32(u32), Gauge32(u32), TimeTicks(u32), Opaque(Bytes), Counter64(u64), NoSuchObject, NoSuchInstance, EndOfMibView, Unknown { tag: u8, data: Bytes, },
}
Expand description

SNMP value.

Represents all SNMP data types including SMIv2 types and exception values.

Variants (Non-exhaustive)§

This enum is marked as non-exhaustive
Non-exhaustive enums could have additional variants added in future. Therefore, when matching against variants of non-exhaustive enums, an extra wildcard arm must be added to account for any future variants.
§

Integer(i32)

INTEGER (ASN.1 primitive, signed 32-bit)

§

OctetString(Bytes)

OCTET STRING (arbitrary bytes).

Per RFC 2578 (SMIv2), OCTET STRING values have a maximum size of 65535 octets. This limit is not enforced during decoding to maintain permissive parsing behavior. Applications that require strict compliance should validate size after decoding.

§

Null

NULL

§

ObjectIdentifier(Oid)

OBJECT IDENTIFIER

§

IpAddress([u8; 4])

IpAddress (4 bytes, big-endian)

§

Counter32(u32)

Counter32 (unsigned 32-bit, wrapping)

§

Gauge32(u32)

Gauge32 / Unsigned32 (unsigned 32-bit, non-wrapping)

§

TimeTicks(u32)

TimeTicks (hundredths of seconds since epoch)

§

Opaque(Bytes)

Opaque (legacy, arbitrary bytes)

§

Counter64(u64)

Counter64 (unsigned 64-bit, wrapping).

SNMPv2c/v3 only. Counter64 was introduced in SNMPv2 (RFC 2578) and is not supported in SNMPv1. When sending Counter64 values to an SNMPv1 agent, the value will be silently ignored or cause an error depending on the agent implementation.

If your application needs to support SNMPv1, avoid using Counter64 or fall back to Counter32 (with potential overflow for high-bandwidth counters).

§

NoSuchObject

noSuchObject exception - OID exists but no value

§

NoSuchInstance

noSuchInstance exception - Instance doesn’t exist

§

EndOfMibView

endOfMibView exception - End of MIB reached during walk

§

Unknown

Unknown/unrecognized value type (for forward compatibility)

Fields

§tag: u8
§data: Bytes

Implementations§

Source§

impl Value

Source

pub fn as_i32(&self) -> Option<i32>

Try to get as i32.

Source

pub fn as_u32(&self) -> Option<u32>

Try to get as u32.

Source

pub fn as_u64(&self) -> Option<u64>

Try to get as u64.

Source

pub fn as_bytes(&self) -> Option<&[u8]>

Try to get as bytes.

Source

pub fn as_str(&self) -> Option<&str>

Try to get as string (UTF-8).

Source

pub fn as_oid(&self) -> Option<&Oid>

Try to get as OID.

Source

pub fn as_ip(&self) -> Option<Ipv4Addr>

Try to get as IP address.

Source

pub fn is_exception(&self) -> bool

Check if this is an exception value.

Source

pub fn format_with_hint(&self, hint: &str) -> Option<String>

Format an OctetString or Opaque value using RFC 2579 DISPLAY-HINT.

Returns None if this is not an OctetString or Opaque value. On invalid hint syntax, falls back to hex encoding.

§Example
use async_snmp::Value;
use bytes::Bytes;

let mac = Value::OctetString(Bytes::from_static(&[0x00, 0x1a, 0x2b, 0x3c, 0x4d, 0x5e]));
assert_eq!(mac.format_with_hint("1x:"), Some("00:1a:2b:3c:4d:5e".into()));

let integer = Value::Integer(42);
assert_eq!(integer.format_with_hint("1d"), None);
Source

pub fn encode(&self, buf: &mut EncodeBuf)

Encode to BER.

Source

pub fn decode(decoder: &mut Decoder) -> Result<Self>

Decode from BER.

Trait Implementations§

Source§

impl Clone for Value

Source§

fn clone(&self) -> Value

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Value

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Display for Value

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl From<&[u8]> for Value

Source§

fn from(data: &[u8]) -> Self

Converts to this type from the input type.
Source§

impl From<&str> for Value

Source§

fn from(s: &str) -> Self

Converts to this type from the input type.
Source§

impl From<[u8; 4]> for Value

Source§

fn from(addr: [u8; 4]) -> Self

Converts to this type from the input type.
Source§

impl From<Bytes> for Value

Source§

fn from(data: Bytes) -> Self

Converts to this type from the input type.
Source§

impl From<Ipv4Addr> for Value

Source§

fn from(addr: Ipv4Addr) -> Self

Converts to this type from the input type.
Source§

impl From<Oid> for Value

Source§

fn from(oid: Oid) -> Self

Converts to this type from the input type.
Source§

impl From<String> for Value

Source§

fn from(s: String) -> Self

Converts to this type from the input type.
Source§

impl From<Value> for GetResult

Source§

fn from(value: Value) -> Self

Converts to this type from the input type.
Source§

impl From<i32> for Value

Source§

fn from(v: i32) -> Self

Converts to this type from the input type.
Source§

impl From<u64> for Value

Source§

fn from(v: u64) -> Self

Converts to this type from the input type.
Source§

impl PartialEq for Value

Source§

fn eq(&self, other: &Value) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl StructuralPartialEq for Value

Auto Trait Implementations§

§

impl !Freeze for Value

§

impl RefUnwindSafe for Value

§

impl Send for Value

§

impl Sync for Value

§

impl Unpin for Value

§

impl UnwindSafe for Value

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more