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 MIBImplementations§
Source§impl View
impl View
Sourcepub fn include(self, oid: Oid) -> Self
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)));Sourcepub fn include_masked(self, oid: Oid, mask: Vec<u8>) -> Self
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.100Sourcepub fn exclude(self, oid: Oid) -> Self
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))); // sysLocationSourcepub fn exclude_masked(self, oid: Oid, mask: Vec<u8>) -> Self
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.
Sourcepub fn contains(&self, oid: &Oid) -> bool
pub fn contains(&self, oid: &Oid) -> bool
Check if an OID is in this view.
Per RFC 3415 Section 5, when multiple subtrees match an OID, the longest matching subtree determines inclusion/exclusion. At equal lengths, exclude wins.
§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 includedSourcepub fn check_subtree(&self, oid: &Oid) -> ViewCheckResult
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:
ViewCheckResult::Included: OID and all descendants are accessibleViewCheckResult::Excluded: OID and all descendants are not accessibleViewCheckResult::Ambiguous: Mixed permissions, check each OID individually
Trait Implementations§
Auto Trait Implementations§
impl Freeze for View
impl RefUnwindSafe for View
impl Send for View
impl Sync for View
impl Unpin for View
impl UnsafeUnpin for View
impl UnwindSafe for View
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more