Skip to main content

SchemaRegistry

Struct SchemaRegistry 

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

Registry holding every loaded schema keyed by (name, version).

Implementations§

Source§

impl SchemaRegistry

Source

pub fn empty() -> Self

Source

pub fn builtin() -> Self

Preloaded with every schema embedded in the binary.

Source

pub fn load_for_workspace( _workspace_root: Option<&Path>, workspace_schemas_dir: Option<&Path>, ) -> Result<Self, WorkspaceSchemaLoadError>

Build a registry starting from the embedded builtins, then layer in the workspace-level shared schemas.

Precedence (highest wins on identical (name, version)):

  1. <workspace_schemas_dir>/<schema>/ — workspace-level shared schemas
  2. Embedded builtins (default@1.0.0, …)

Different versions of the same schema coexist; a mem picks by exact pin via MemConfig.schema.

Hidden directories (name starts with .) are skipped at every scan level so VCS metadata and OS dotdirs cannot be mistaken for a schema definition.

Returns the first validation failure it hits so a broken schema can never silently shadow a working builtin.

A third pass over <workspace_root>/.memstead.cache/schemas/ used to sit underneath these two, meant to carry schemas extracted from installed archives. Nothing ever wrote that directory, so it only ever contributed the illusion of a staging mechanism; installs now stage into the backend’s own schema source, which is the storage the pin resolver actually reads. workspace_root is retained because callers pass it and future storage-rooted passes belong here.

workspace_root and workspace_schemas_dir are independent optionals: passing None for both yields the builtins-only registry (the Engine::init no-settings variant).

Source

pub fn resolve_by_name( &self, name: &str, ) -> Result<Option<Arc<Schema>>, SchemaNameAmbiguous>

Resolve a schema by name alone. Used by the memstead_schema(name=...) lookup surface: the registry is expected to hold at most one schema with the given name after workspace-level loading.

Returns:

  • Ok(Some(schema)) when exactly one schema is registered with this name (any version — the version is metadata).
  • Ok(None) when no schema with that name is registered.
  • Err(SchemaNameAmbiguous) when multiple versions of the same name are registered (cache + builtin collision, or mixed workspace-level versions). Callers surface this — bare-name lookups need a unique winner.
Source

pub fn merge_from(&mut self, other: &SchemaRegistry)

Merge another registry into this one. name@version keys already present are left untouched — the caller controls precedence by the order it merges. Used by the engine to build one aggregate registry across writable mems without copying arcs twice.

Source

pub fn insert_overwriting(&mut self, schema: Arc<Schema>)

Insert a schema, replacing any existing entry at the same (name, version) key. Used by storage backends that source workspace-level schemas from outside the disk-walker (e.g. the gix-tree-backed loader in memstead-git-branch::mem_repo_schemas) to overlay workspace schemas on top of the cache + builtins layers loaded by Self::load_for_workspace with workspace_schemas_dir = None.

Shadowing semantics: this method overwrites builtin entries at the same (name, version). That is intentional for the canonical use case — a workspace’s software@1.0.0 schema overlay legitimately replaces the default@1.0.0 builtin’s slot only when the names happen to collide, which is the mem-repo overlay pattern. Callers MUST NOT use this method to silently shadow an unrelated builtin name unless they own the workspace-overlay precedence story; the only in-tree caller is memstead-git-branch::lib::build_workspace_schema_registry.

Source

pub fn get(&self, name: &str, version: &Version) -> Option<Arc<Schema>>

Source

pub fn iter(&self) -> impl Iterator<Item = Arc<Schema>> + '_

Source

pub fn available_versions(&self, name: &str) -> Vec<Version>

Source

pub fn suggest_name(&self, name: &str) -> Option<String>

Closest-match schema name by Levenshtein edit distance against the currently-registered schemas. Returns None if the registry is empty or every candidate’s distance from name is 0 (exact match, shouldn’t be called in that case) — callers get a clean Option to plug into error messages without format-plumbing.

Source

pub fn identities(&self) -> Vec<(String, Version)>

List every registered (name, version) pair, stably sorted so iteration is deterministic.

Source

pub fn is_empty(&self) -> bool

Source

pub fn len(&self) -> usize

Source

pub fn insert(&mut self, schema: Arc<Schema>) -> Result<(), SchemaRegistryError>

Trait Implementations§

Source§

impl Debug for SchemaRegistry

Source§

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

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

impl Default for SchemaRegistry

Source§

fn default() -> Self

Returns the “default value” for a type. 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<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, 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.