Trait ModuleStore

Source
pub trait ModuleStore {
Show 17 methods // Required methods fn len(&self) -> usize; fn contains(&self, name: &Identifier) -> bool; fn get(&self, name: &Identifier) -> Option<&Module>; fn get_mut(&mut self, name: &Identifier) -> Option<&mut Module>; fn modules(&self) -> impl Iterator<Item = &Module>; fn module_names(&self) -> impl Iterator<Item = &Identifier>; fn insert(&mut self, module: Module); fn remove(&mut self, name: &Identifier) -> bool; fn uri_to_module_name(&self, url: &Url) -> Option<&Identifier>; fn module_name_to_uri(&self, name: &Identifier) -> Option<&Url>; // Provided methods fn is_empty(&self) -> bool { ... } fn contains_by_uri(&self, uri: &Url) -> bool { ... } fn get_by_uri(&self, uri: &Url) -> Option<&Module> { ... } fn get_by_uri_mut(&mut self, uri: &Url) -> Option<&mut Module> { ... } fn remove_by_uri(&mut self, uri: &Url) -> bool { ... } fn resolve(&self, definition: &QualifiedIdentifier) -> Option<&Definition> { ... } fn resolve_or_in( &self, definition: &IdentifierReference, in_module: &Identifier, ) -> Option<&Definition> { ... }
}
Expand description

A trait for any type that /stores/ modules and can retrieve them by name and by URI.

Required Methods§

Source

fn len(&self) -> usize

Return the number of modules in the store.

Source

fn contains(&self, name: &Identifier) -> bool

Returns true if the loader’s cache contains a module with the name name, else false.

Source

fn get(&self, name: &Identifier) -> Option<&Module>

Returns a reference to the Module identified by name if the store contains it; else None.

Source

fn get_mut(&mut self, name: &Identifier) -> Option<&mut Module>

Returns a mutable reference to the Module identified by name if the store contains it; else None.

Source

fn modules(&self) -> impl Iterator<Item = &Module>

Return an iterator over all modules in this store. This may be an expensive operation if modules only exist in some backing store.

Source

fn module_names(&self) -> impl Iterator<Item = &Identifier>

Return an iterator over the names of the modules in this store.

Source

fn insert(&mut self, module: Module)

Insert module into the store.

Source

fn remove(&mut self, name: &Identifier) -> bool

Remove any module identified by name.

Source

fn uri_to_module_name(&self, url: &Url) -> Option<&Identifier>

Return the module name corresponding to the provided url if it exists, or else None.

Source

fn module_name_to_uri(&self, name: &Identifier) -> Option<&Url>

Return the module URI corresponding to the provided name if it exists, or else None.

Provided Methods§

Source

fn is_empty(&self) -> bool

Return true if there are no modules in this store, else false.

Source

fn contains_by_uri(&self, uri: &Url) -> bool

Returns true if the loader’s cache contains a module with the base URI uri, else false.

Source

fn get_by_uri(&self, uri: &Url) -> Option<&Module>

Returns a reference to the Module identified by uri if the store contains it; else None.

Source

fn get_by_uri_mut(&mut self, uri: &Url) -> Option<&mut Module>

Returns a mutable reference to the Module identified by uri if the store contains it; else None.

Source

fn remove_by_uri(&mut self, uri: &Url) -> bool

Remove any module identified by uri.

Source

fn resolve(&self, definition: &QualifiedIdentifier) -> Option<&Definition>

Given a qualified identifier, find the named module or return None, then find the named member in the found module or return None.

§Example
use sdml_core::model::identifiers::QualifiedIdentifier;
use sdml_core::store::{InMemoryModuleCache, ModuleStore};
use std::str::FromStr;

let cache = InMemoryModuleCache::with_stdlib();
let name = QualifiedIdentifier::from_str("xsd:integer").unwrap();
let integer = cache.resolve(&name).unwrap();
println!("{integer:?}");
Source

fn resolve_or_in( &self, definition: &IdentifierReference, in_module: &Identifier, ) -> Option<&Definition>

If definition is a QualifiedIdentifier this is the same as resolve; however, if definition is an Identifier then look for definition in the module named in_module.

§Example
use sdml_core::model::identifiers::{Identifier, IdentifierReference};
use sdml_core::store::{InMemoryModuleCache, ModuleStore};
use std::str::FromStr;

let cache = InMemoryModuleCache::with_stdlib();
let default_module = Identifier::from_str("xsd").unwrap();
let name = IdentifierReference::from_str("integer").unwrap();
let integer = cache.resolve_or_in(&name, &default_module).unwrap();
println!("{integer:?}");

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§