pub struct Loader { /* private fields */ }Expand description
Builder for loading and resolving MIB modules.
Typical usage starts with Loader::new, adds one or more Sources,
optionally restricts the requested modules, and finishes with
Loader::load.
If no module list is provided, all modules visible from the configured sources are loaded.
§Examples
Load a specific module from a directory:
use mib_rs::Loader;
let mib = Loader::new()
.source(mib_rs::source::dir("/usr/share/snmp/mibs").unwrap())
.modules(["IF-MIB"])
.load()
.expect("load failed");Load from an in-memory source:
use mib_rs::Loader;
let src = mib_rs::source::memory("MY-MIB", b"MY-MIB DEFINITIONS ::= BEGIN END".as_slice());
let mib = Loader::new()
.source(src)
.load()
.expect("load failed");Implementations§
Source§impl Loader
impl Loader
Sourcepub fn new() -> Self
pub fn new() -> Self
Create a new loader with no sources.
Uses ResolverStrictness::Normal and the default DiagnosticConfig.
Sourcepub fn source(self, src: Box<dyn Source>) -> Self
pub fn source(self, src: Box<dyn Source>) -> Self
Add a MIB source.
Sources are searched in the order they are added. When the same module is available from multiple sources, the first matching source wins.
Sourcepub fn sources(self, srcs: Vec<Box<dyn Source>>) -> Self
pub fn sources(self, srcs: Vec<Box<dyn Source>>) -> Self
Add multiple MIB sources.
Sources are appended in order and searched left-to-right.
Sourcepub fn modules(self, names: impl IntoIterator<Item = impl Into<String>>) -> Self
pub fn modules(self, names: impl IntoIterator<Item = impl Into<String>>) -> Self
Restrict loading to the named modules and their transitive dependencies.
When omitted, all modules from the configured sources are loaded.
Sourcepub fn diagnostic_config(self, config: DiagnosticConfig) -> Self
pub fn diagnostic_config(self, config: DiagnosticConfig) -> Self
Set the DiagnosticConfig controlling which diagnostics are
reported and which severity triggers a LoadError::DiagnosticThreshold.
Sourcepub fn resolver_strictness(self, strictness: ResolverStrictness) -> Self
pub fn resolver_strictness(self, strictness: ResolverStrictness) -> Self
Set the ResolverStrictness level used during resolution.
Sourcepub fn system_paths(self) -> Self
pub fn system_paths(self) -> Self
Enable automatic discovery of system MIB directories.
Probes net-snmp and libsmi config files and environment variables.
Discovered paths are appended after any explicitly added sources.
See searchpath::discover_system_paths for details.
Source§impl Loader
impl Loader
Sourcepub fn load(self) -> Result<Mib, LoadError>
pub fn load(self) -> Result<Mib, LoadError>
Execute the full load pipeline and return the resolved Mib.
Runs source discovery, parallel parsing, lowering, and resolution.
§Errors
Returns LoadError::NoSources if no sources are configured,
LoadError::MissingModules if explicitly requested modules cannot
be found, LoadError::DiagnosticThreshold if any diagnostic
exceeds the configured severity threshold, or LoadError::Io on
file read failures.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Loader
impl !RefUnwindSafe for Loader
impl Send for Loader
impl Sync for Loader
impl Unpin for Loader
impl UnsafeUnpin for Loader
impl !UnwindSafe for Loader
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> 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