pub struct SchemaRegistry { /* private fields */ }Expand description
Registry holding every loaded schema keyed by (name, version).
Implementations§
Source§impl SchemaRegistry
impl SchemaRegistry
pub fn empty() -> Self
Sourcepub fn load_for_workspace(
workspace_root: Option<&Path>,
workspace_schemas_dir: Option<&Path>,
) -> Result<Self, WorkspaceSchemaLoadError>
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 and the workspace-wide schema cache.
Precedence (highest wins on identical (name, version)):
<workspace_schemas_dir>/<schema>/— workspace-level shared schemas- Embedded builtins (
default@1.0.0, …) <workspace_root>/.memstead.cache/schemas/<schema>-<version>/— extracted from read-mem archives (workspace-wide cache)
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. Two distinct cache
directories sharing the same <name>-<version> key surface as
WorkspaceSchemaLoadError::CacheCollision — the extraction
pipeline must guarantee uniqueness, and silent overwrite would mask
the bug.
workspace_root and workspace_schemas_dir are independent
optionals: passing None for both yields the builtins-only registry
(the Engine::init no-settings variant).
Sourcepub fn resolve_by_name(
&self,
name: &str,
) -> Result<Option<Arc<Schema>>, SchemaNameAmbiguous>
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.
Sourcepub fn merge_from(&mut self, other: &SchemaRegistry)
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.
Sourcepub fn insert_overwriting(&mut self, schema: Arc<Schema>)
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.
pub fn get(&self, name: &str, version: &Version) -> Option<Arc<Schema>>
pub fn iter(&self) -> impl Iterator<Item = Arc<Schema>> + '_
pub fn available_versions(&self, name: &str) -> Vec<Version>
Sourcepub fn suggest_name(&self, name: &str) -> Option<String>
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.
Sourcepub fn identities(&self) -> Vec<(String, Version)>
pub fn identities(&self) -> Vec<(String, Version)>
List every registered (name, version) pair, stably sorted so
iteration is deterministic.