pub struct YangLibraryReference { /* private fields */ }Expand description
A reference to a YANG Library stored on disk.
This structure provides a lightweight handle to a YANG library without loading all the module contents into memory. It stores the essential information needed to locate and load the YANG library and its associated modules on demand.
§Multi-Subscription Support
A single YangLibraryReference can be associated with multiple
subscriptions from different peers, as long as they all use the same YANG
library (content-id).
subscriptions_info: Retrieve all associated subscriptionsappend_subscription_info: Add another subscriptionsave_to_disk: Persist YANG library and subscriptions
§Components
-
Content ID: A unique identifier for the YANG library, extracted from the library itself during construction to ensure consistency.
-
YANG Library Path: The filesystem path to the serialized YANG library XML file (
yang-lib.xml). -
YANG Library Reference Directory: The directory containing the
yang-lib.xml,subscriptions-info.jsonandmodulesdirectory containing YANG modules referenced by the library. Modules are loaded from{yang_lib_ref_path}/modulesin this directory whenload_schemasis called.
§Lazy Loading
The reference is designed for lazy loading - it validates that the paths
exist and extracts the content ID during construction, but does not load
the full YANG library or module contents until explicitly requested via
yang_library or
load_schemas.
§Example
use std::path::PathBuf;
// Create a reference to an existing YANG library on disk
let yang_lib_ref = YangLibraryReference::new(
PathBuf::from("/schemas/content-id-123/yang-lib.xml"),
PathBuf::from("/schemas/content-id-123"),
)?;
// Access the content ID (available immediately)
let content_id = yang_lib_ref.content_id();
// Load the full YANG library when needed
let yang_library = yang_lib_ref.yang_library()?;
// Load all module schemas from disk
let schemas = yang_lib_ref.load_schemas()?;§Errors
Construction will fail if:
- The YANG library path does not exist or is not a file
- The search directory does not exist or is not a directory
- The YANG library XML cannot be parsed
Implementations§
Source§impl YangLibraryReference
impl YangLibraryReference
Sourcepub fn load_from_disk(
yang_library_path: PathBuf,
yang_lib_ref_path: PathBuf,
) -> Result<Self, YangLibraryCacheError>
pub fn load_from_disk( yang_library_path: PathBuf, yang_lib_ref_path: PathBuf, ) -> Result<Self, YangLibraryCacheError>
Load a YANG Library Reference from the given YANG Library file path and root directory for the YANG Library reference.
Note: the content ID is read from the YANG Library file to ensure its correctness.
This does not load the YANG modules themselves, only the reference to them.
Sourcepub fn save_to_disk(
yang_lib_ref_path: PathBuf,
yang_library: &YangLibrary,
schemas: HashMap<Box<str>, Box<str>>,
subscriptions_info: &[SubscriptionInfo],
) -> Result<Self, YangLibraryCacheError>
pub fn save_to_disk( yang_lib_ref_path: PathBuf, yang_library: &YangLibrary, schemas: HashMap<Box<str>, Box<str>>, subscriptions_info: &[SubscriptionInfo], ) -> Result<Self, YangLibraryCacheError>
Create and save a YANG Library Reference to disk.
This will create the necessary directory structure and files to store the YANG library, subscription info, and YANG modules.
If the YANG Library already exists on disk and differs from the provided YANG Library, an error is returned to prevent overwriting.
If the YANG Library already exists and is identical, the existing reference is returned and the subscription info is extended with the new subscriptions.
Sourcepub const fn content_id(&self) -> &ContentId
pub const fn content_id(&self) -> &ContentId
Get the content ID of the YANG Library.
Sourcepub fn yang_library_path(&self) -> &Path
pub fn yang_library_path(&self) -> &Path
Get the path to the YANG Library file.
Sourcepub fn yang_library(&self) -> Result<YangLibrary, YangLibraryCacheError>
pub fn yang_library(&self) -> Result<YangLibrary, YangLibraryCacheError>
Load the YANG Library from disk.
Sourcepub fn yang_lib_ref_path(&self) -> &Path
pub fn yang_lib_ref_path(&self) -> &Path
Get the path to the directory containing the YANG Library file.
Sourcepub fn search_dir(&self) -> PathBuf
pub fn search_dir(&self) -> PathBuf
Get the path to the search directory containing the YANG modules.
Sourcepub fn load_schemas(
&self,
) -> Result<HashMap<Box<str>, Box<str>>, YangLibraryCacheError>
pub fn load_schemas( &self, ) -> Result<HashMap<Box<str>, Box<str>>, YangLibraryCacheError>
Load the YANG schemas defined in the library from disk.
pub fn subscription_info_path(&self) -> PathBuf
pub fn subscriptions_info( &self, ) -> Result<Vec<SubscriptionInfo>, YangLibraryCacheError>
Sourcepub fn append_subscription_info(
&self,
subscription_info: SubscriptionInfo,
) -> Result<(), YangLibraryCacheError>
pub fn append_subscription_info( &self, subscription_info: SubscriptionInfo, ) -> Result<(), YangLibraryCacheError>
Appends a subscription information entry to the persisted list.
If the subscription info already exists, this operation is idempotent (no duplicate entry is created). Uses file locking to prevent concurrent modification issues and atomic writes for crash safety.
§Errors
Returns an error if:
- The subscription info file cannot be accessed
- JSON parsing/serialization fails
- File system operations fail
Sourcepub fn remove_subscription_info(
&self,
subscription_info: &SubscriptionInfo,
) -> Result<Option<SubscriptionInfo>, YangLibraryCacheError>
pub fn remove_subscription_info( &self, subscription_info: &SubscriptionInfo, ) -> Result<Option<SubscriptionInfo>, YangLibraryCacheError>
Remove a subscription info from the YANG library reference.
If the subscription info is found and removed, it is returned. If not found, None is returned.
Trait Implementations§
Source§impl Clone for YangLibraryReference
impl Clone for YangLibraryReference
Source§impl Debug for YangLibraryReference
impl Debug for YangLibraryReference
Source§impl<'de> Deserialize<'de> for YangLibraryReference
impl<'de> Deserialize<'de> for YangLibraryReference
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
impl Eq for YangLibraryReference
Source§impl Hash for YangLibraryReference
impl Hash for YangLibraryReference
Source§impl PartialEq for YangLibraryReference
impl PartialEq for YangLibraryReference
Source§impl Serialize for YangLibraryReference
impl Serialize for YangLibraryReference
impl StructuralPartialEq for YangLibraryReference
Auto Trait Implementations§
impl Freeze for YangLibraryReference
impl RefUnwindSafe for YangLibraryReference
impl Send for YangLibraryReference
impl Sync for YangLibraryReference
impl Unpin for YangLibraryReference
impl UnsafeUnpin for YangLibraryReference
impl UnwindSafe for YangLibraryReference
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> DeserializeOwned for Twhere
T: for<'de> Deserialize<'de>,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<T> FutureExt for T
impl<T> FutureExt for T
Source§fn with_context(self, otel_cx: Context) -> WithContext<Self> ⓘ
fn with_context(self, otel_cx: Context) -> WithContext<Self> ⓘ
Source§fn with_current_context(self) -> WithContext<Self> ⓘ
fn with_current_context(self) -> WithContext<Self> ⓘ
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