Skip to main content

YangLibraryReference

Struct YangLibraryReference 

Source
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).

§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.json and modules directory containing YANG modules referenced by the library. Modules are loaded from {yang_lib_ref_path}/modules in this directory when load_schemas is 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

Source

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.

Source

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.

Source

pub const fn content_id(&self) -> &ContentId

Get the content ID of the YANG Library.

Source

pub fn yang_library_path(&self) -> &Path

Get the path to the YANG Library file.

Source

pub fn yang_library(&self) -> Result<YangLibrary, YangLibraryCacheError>

Load the YANG Library from disk.

Source

pub fn yang_lib_ref_path(&self) -> &Path

Get the path to the directory containing the YANG Library file.

Source

pub fn search_dir(&self) -> PathBuf

Get the path to the search directory containing the YANG modules.

Source

pub fn load_schemas( &self, ) -> Result<HashMap<Box<str>, Box<str>>, YangLibraryCacheError>

Load the YANG schemas defined in the library from disk.

Source

pub fn subscription_info_path(&self) -> PathBuf

Source

pub fn subscriptions_info( &self, ) -> Result<Vec<SubscriptionInfo>, YangLibraryCacheError>

Source

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
Source

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

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for YangLibraryReference

Source§

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

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

impl<'de> Deserialize<'de> for YangLibraryReference

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Eq for YangLibraryReference

Source§

impl Hash for YangLibraryReference

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl PartialEq for YangLibraryReference

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl Serialize for YangLibraryReference

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl StructuralPartialEq for YangLibraryReference

Auto Trait Implementations§

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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

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> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> FutureExt for T

Source§

fn with_context(self, otel_cx: Context) -> WithContext<Self> ⓘ

Attaches the provided Context to this type, returning a WithContext wrapper. Read more
Source§

fn with_current_context(self) -> WithContext<Self> ⓘ

Attaches the current Context to this type, returning a WithContext wrapper. Read more
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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

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 = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

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<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

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