Skip to main content

RdmCache

Struct RdmCache 

Source
pub struct RdmCache { /* private fields */ }
Expand description

Cache for RDM collections, enabling concept UUID -> label lookups

Implementations§

Source§

impl RdmCache

Source

pub fn new() -> Self

Create a new empty cache

Source

pub fn add_collection_from_json( &mut self, collection_id: &str, concepts_json: &str, ) -> Result<(), String>

Add a collection from JSON

@param collection_id - The collection identifier @param concepts_json - JSON array of concepts with {id, prefLabel: {lang: label}}

Source

pub fn add_collection(&mut self, collection: RdmCollection)

Add a collection, merging with any existing collection that has the same ID.

When merging:

  • New concepts with labels always win over existing bare stubs (no labels).
  • Existing concepts with labels are kept if the incoming concept is bare.
  • If both have labels, the incoming concept wins (last-writer-wins).
  • New concepts that don’t exist yet are always added.
Source

pub fn has_collection(&self, collection_id: &str) -> bool

Check if a collection is loaded

Source

pub fn get_collection_ids(&self) -> Vec<String>

Get all loaded collection IDs

Source

pub fn lookup_label( &self, collection_id: &str, concept_id: &str, language: &str, ) -> Option<String>

Look up the label for a concept

@param collection_id - The collection to search in @param concept_id - The concept UUID @param language - The language code (e.g., “en”) @returns The label string, or None if not found

Source

pub fn lookup_concept( &self, collection_id: &str, concept_id: &str, ) -> Option<&RdmConcept>

Look up full concept info

Source

pub fn get_parent_id( &self, collection_id: &str, concept_id: &str, ) -> Option<String>

Get the first parent ID for a concept

Returns None if the collection doesn’t exist, concept doesn’t exist, or concept has no parent (top-level concept).

Source

pub fn lookup_value( &self, collection_id: &str, value_id: &str, ) -> Option<&RdmValue>

Look up a value by its VALUE ID

This is the primary lookup method used by ViewModels. Returns None if the collection or value ID is not found.

Source

pub fn get_concept_id_for_value( &self, collection_id: &str, value_id: &str, ) -> Option<&str>

Get concept ID from value ID

Returns the concept ID that contains the given value ID.

Source

pub fn validate_value(&self, collection_id: &str, value_id: &str) -> bool

Validate that a value exists in a collection

Source

pub fn get_collection(&self, collection_id: &str) -> Option<&RdmCollection>

Get a collection by ID

Source

pub fn get_collection_mut( &mut self, collection_id: &str, ) -> Option<&mut RdmCollection>

Get a mutable reference to a collection by ID

Source

pub fn clear(&mut self)

Clear all cached collections

Source

pub fn remove_collection(&mut self, collection_id: &str) -> bool

Remove a specific collection from the cache

Source

pub fn len(&self) -> usize

Get the number of cached collections

Source

pub fn is_empty(&self) -> bool

Check if the cache is empty

Source

pub fn validate_concept(&self, collection_id: &str, concept_id: &str) -> bool

Validate that a concept exists in a collection

Source

pub fn lookup_by_label( &self, collection_id: &str, label: &str, ) -> Option<&RdmConcept>

Look up a concept by label in a specific collection

Returns the concept if exactly one match is found. Returns None if no match or ambiguous (multiple matches).

Source

pub fn lookup_all_by_label( &self, collection_id: &str, label: &str, ) -> Vec<&RdmConcept>

Look up a concept by label, returning all matches

Source

pub fn search_all( &self, query: &str, language: Option<&str>, ) -> Vec<(&str, &RdmConcept)>

Search across all collections (for autocomplete)

Source§

impl RdmCache

Source

pub fn add_from_skos_collection(&mut self, skos: &SkosCollection) -> String

Convert a SkosCollection to an RdmCollection and add it to the cache.

Returns the collection ID.

Source

pub fn add_from_skos_collections( &mut self, collections: &[SkosCollection], ) -> Vec<String>

Add multiple SKOS collections to the cache.

After adding, enriches any existing collections that have bare concept stubs (concepts with no labels) if the newly-added data provides labels for those concept IDs. This handles the common Arches pattern where collections.xml and concepts.xml are separate files.

Returns the list of collection IDs added.

Trait Implementations§

Source§

impl Clone for RdmCache

Source§

fn clone(&self) -> RdmCache

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 ConceptLookup for RdmCache

Source§

fn lookup_by_label(&self, collection_id: &str, label: &str) -> Option<String>

Look up a concept ID by its label in a specific collection. Returns None if not found or ambiguous.
Source§

impl Debug for RdmCache

Source§

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

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

impl Default for RdmCache

Source§

fn default() -> RdmCache

Returns the “default value” for a type. Read more
Source§

impl ExternalResolver for RdmCache

Source§

fn resolve_concept( &self, collection_id: &str, concept_id: &str, language: &str, ) -> Option<String>

Resolve a concept UUID to its display label. Read more

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> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

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

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.