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 diagnostic collection,
severity overrides, and the 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.
Sourcepub fn parallelism(self, threads: usize) -> Self
pub fn parallelism(self, threads: usize) -> Self
Set the number of threads used when loading all discoverable modules.
Defaults to the number of available logical CPUs. Set to 1 to
disable parallel loading. Loading a selected module list with
Loader::modules and resolving parsed modules are sequential.
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.