View

Struct View 

Source
pub struct View { /* private fields */ }
Expand description

A view is a collection of OID subtrees defining accessible objects.

Views are used by VACM to determine which OIDs a user can access. Each view consists of included and/or excluded subtrees.

§Example

use async_snmp::agent::View;
use async_snmp::oid;

// Create a view that includes the system MIB but excludes sysContact
let view = View::new()
    .include(oid!(1, 3, 6, 1, 2, 1, 1))        // system MIB
    .exclude(oid!(1, 3, 6, 1, 2, 1, 1, 4));    // sysContact

assert!(view.contains(&oid!(1, 3, 6, 1, 2, 1, 1, 1, 0)));   // sysDescr.0
assert!(!view.contains(&oid!(1, 3, 6, 1, 2, 1, 1, 4, 0)));  // sysContact.0
assert!(!view.contains(&oid!(1, 3, 6, 1, 2, 1, 2)));        // interfaces MIB

Implementations§

Source§

impl View

Source

pub fn new() -> Self

Create a new empty view.

An empty view contains no OIDs. Add subtrees with include() or exclude().

Source

pub fn include(self, oid: Oid) -> Self

Add an included subtree to the view.

All OIDs starting with oid will be included in the view, unless excluded by a later exclude() call.

§Example
use async_snmp::agent::View;
use async_snmp::oid;

let view = View::new()
    .include(oid!(1, 3, 6, 1, 2, 1))  // MIB-2
    .include(oid!(1, 3, 6, 1, 4, 1)); // enterprises

assert!(view.contains(&oid!(1, 3, 6, 1, 2, 1, 1, 0)));
assert!(view.contains(&oid!(1, 3, 6, 1, 4, 1, 99999, 1)));
Source

pub fn include_masked(self, oid: Oid, mask: Vec<u8>) -> Self

Add an included subtree with a wildcard mask.

The mask allows wildcards at specific OID arc positions. See ViewSubtree::mask for mask format details.

§Example
use async_snmp::agent::View;
use async_snmp::oid;

// Include ifDescr for any interface (mask makes arc 10 a wildcard)
let view = View::new()
    .include_masked(
        oid!(1, 3, 6, 1, 2, 1, 2, 2, 1, 2),  // ifDescr
        vec![0xFF, 0xC0]  // First 10 arcs must match
    );

assert!(view.contains(&oid!(1, 3, 6, 1, 2, 1, 2, 2, 1, 2, 1)));   // ifDescr.1
assert!(view.contains(&oid!(1, 3, 6, 1, 2, 1, 2, 2, 1, 2, 100))); // ifDescr.100
Source

pub fn exclude(self, oid: Oid) -> Self

Add an excluded subtree to the view.

OIDs starting with oid will be excluded, even if they match an included subtree. Exclusions take precedence.

§Example
use async_snmp::agent::View;
use async_snmp::oid;

let view = View::new()
    .include(oid!(1, 3, 6, 1, 2, 1, 1))     // system MIB
    .exclude(oid!(1, 3, 6, 1, 2, 1, 1, 6)); // except sysLocation

assert!(view.contains(&oid!(1, 3, 6, 1, 2, 1, 1, 1, 0)));  // sysDescr
assert!(!view.contains(&oid!(1, 3, 6, 1, 2, 1, 1, 6, 0))); // sysLocation
Source

pub fn exclude_masked(self, oid: Oid, mask: Vec<u8>) -> Self

Add an excluded subtree with a wildcard mask.

See include_masked() for mask usage.

Source

pub fn contains(&self, oid: &Oid) -> bool

Check if an OID is in this view.

Per RFC 3415 Section 5, an OID is in the view if:

  • At least one included subtree matches, AND
  • No excluded subtree matches
§Example
use async_snmp::agent::View;
use async_snmp::oid;

let view = View::new()
    .include(oid!(1, 3, 6, 1, 2, 1))
    .exclude(oid!(1, 3, 6, 1, 2, 1, 25));  // host resources

assert!(view.contains(&oid!(1, 3, 6, 1, 2, 1, 1, 0)));
assert!(!view.contains(&oid!(1, 3, 6, 1, 2, 1, 25, 1, 0)));
assert!(!view.contains(&oid!(1, 3, 6, 1, 4, 1)));  // not included
Source

pub fn check_subtree(&self, oid: &Oid) -> ViewCheckResult

Check subtree access status with 3-state result.

Unlike contains() which checks a single OID, this method determines the access status for an entire subtree. This enables optimizations for GETBULK/GETNEXT operations.

Returns:

Trait Implementations§

Source§

impl Clone for View

Source§

fn clone(&self) -> View

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 View

Source§

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

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

impl Default for View

Source§

fn default() -> View

Returns the “default value” for a type. Read more

Auto Trait Implementations§

§

impl Freeze for View

§

impl RefUnwindSafe for View

§

impl Send for View

§

impl Sync for View

§

impl Unpin for View

§

impl UnwindSafe for View

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, 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