pub struct SpecRegistry {
exact_specs: BTreeMap<String, FunctionSpec>,
pattern_specs: Vec<(NamePattern, FunctionSpec)>,
loaded_paths: Vec<PathBuf>,
warnings: Vec<String>,
}Expand description
A registry of function specifications.
Provides lookup by function name with support for exact matches, glob patterns, and regex patterns.
Fields§
§exact_specs: BTreeMap<String, FunctionSpec>Merged specs indexed by exact name.
pattern_specs: Vec<(NamePattern, FunctionSpec)>Pattern-based specs (glob and regex).
loaded_paths: Vec<PathBuf>Paths that were loaded (for diagnostics).
warnings: Vec<String>Warnings generated during loading.
Implementations§
Source§impl SpecRegistry
impl SpecRegistry
Sourcepub fn load() -> Result<Self, RegistryError>
pub fn load() -> Result<Self, RegistryError>
Load specs from default discovery paths.
Discovery order (later overrides earlier per-function):
<binary>/../share/saf/specs/*.yaml— shipped defaults~/.saf/specs/*.yaml— user global./saf-specs/*.yaml— project local$SAF_SPECS_PATH/*.yaml— explicit override (if set)
§Errors
Returns an error if any spec file fails to parse.
Sourcepub fn load_from(paths: &[PathBuf]) -> Result<Self, RegistryError>
pub fn load_from(paths: &[PathBuf]) -> Result<Self, RegistryError>
Load specs from specific paths only.
Each path can be a file or directory. Directories are scanned for *.yaml files.
§Errors
Returns an error if any path fails to load.
Sourcefn load_directory(&mut self, dir: &Path) -> Result<(), RegistryError>
fn load_directory(&mut self, dir: &Path) -> Result<(), RegistryError>
Load specs from a directory.
Sourcefn load_file(&mut self, path: &Path) -> Result<(), RegistryError>
fn load_file(&mut self, path: &Path) -> Result<(), RegistryError>
Load specs from a single file.
Sourcefn insert(&mut self, spec: FunctionSpec) -> Result<(), RegistryError>
fn insert(&mut self, spec: FunctionSpec) -> Result<(), RegistryError>
Insert a spec into the registry.
For exact names: merges with existing spec (new overrides old). For patterns: appends to pattern list.
Sourcepub fn lookup(&self, name: &str) -> Option<&FunctionSpec>
pub fn lookup(&self, name: &str) -> Option<&FunctionSpec>
Look up a function spec by name.
Returns the first matching spec:
- Exact match has highest priority
- Pattern matches are checked in order (last loaded wins)
Returns None for disabled specs.
Sourcepub fn iter(&self) -> impl Iterator<Item = &FunctionSpec>
pub fn iter(&self) -> impl Iterator<Item = &FunctionSpec>
Iterate over all exact-match specs.
Sourcepub fn patterns(&self) -> impl Iterator<Item = &FunctionSpec>
pub fn patterns(&self) -> impl Iterator<Item = &FunctionSpec>
Iterate over all pattern-based specs.
Sourcepub fn loaded_paths(&self) -> &[PathBuf]
pub fn loaded_paths(&self) -> &[PathBuf]
Get paths that were loaded.
Sourcefn discovery_paths() -> Vec<PathBuf>
fn discovery_paths() -> Vec<PathBuf>
Get default discovery paths.
Sourcepub fn add(&mut self, spec: FunctionSpec) -> Result<(), RegistryError>
pub fn add(&mut self, spec: FunctionSpec) -> Result<(), RegistryError>
Add a spec directly (for programmatic construction).
§Errors
Returns an error if the spec has a duplicate function name.
Sourcepub fn from_yaml(yaml: &str) -> Result<Self, RegistryError>
pub fn from_yaml(yaml: &str) -> Result<Self, RegistryError>
Create a registry from a YAML string (for testing and programmatic use).
§Errors
Returns an error if the YAML is invalid.
Sourcepub fn from_yaml_strs(yamls: &[String]) -> Result<Self, RegistryError>
pub fn from_yaml_strs(yamls: &[String]) -> Result<Self, RegistryError>
Build a SpecRegistry from multiple raw YAML strings.
Used by the WASM frontend where filesystem access is unavailable.
Each string should be a complete spec file (with version and specs keys).
§Errors
Returns an error if any YAML string fails to parse.
Sourcepub fn warn_missing(&self, name: &str)
pub fn warn_missing(&self, name: &str)
Report missing spec warning.