Skip to main content

SpecRegistry

Struct SpecRegistry 

Source
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

Source

pub fn new() -> Self

Create an empty registry.

Source

pub fn load() -> Result<Self, RegistryError>

Load specs from default discovery paths.

Discovery order (later overrides earlier per-function):

  1. <binary>/../share/saf/specs/*.yaml — shipped defaults
  2. ~/.saf/specs/*.yaml — user global
  3. ./saf-specs/*.yaml — project local
  4. $SAF_SPECS_PATH/*.yaml — explicit override (if set)
§Errors

Returns an error if any spec file fails to parse.

Source

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.

Source

fn load_directory(&mut self, dir: &Path) -> Result<(), RegistryError>

Load specs from a directory.

Source

fn load_file(&mut self, path: &Path) -> Result<(), RegistryError>

Load specs from a single file.

Source

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.

Source

pub fn lookup(&self, name: &str) -> Option<&FunctionSpec>

Look up a function spec by name.

Returns the first matching spec:

  1. Exact match has highest priority
  2. Pattern matches are checked in order (last loaded wins)

Returns None for disabled specs.

Source

pub fn iter(&self) -> impl Iterator<Item = &FunctionSpec>

Iterate over all exact-match specs.

Source

pub fn patterns(&self) -> impl Iterator<Item = &FunctionSpec>

Iterate over all pattern-based specs.

Source

pub fn len(&self) -> usize

Get the number of exact-match specs.

Source

pub fn is_empty(&self) -> bool

Check if the registry is empty.

Source

pub fn loaded_paths(&self) -> &[PathBuf]

Get paths that were loaded.

Source

pub fn warnings(&self) -> &[String]

Get warnings generated during loading.

Source

fn discovery_paths() -> Vec<PathBuf>

Get default discovery paths.

Source

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.

Source

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.

Source

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.

Source

pub fn warn_missing(&self, name: &str)

Report missing spec warning.

Trait Implementations§

Source§

impl Debug for SpecRegistry

Source§

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

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

impl Default for SpecRegistry

Source§

fn default() -> SpecRegistry

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.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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.
§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more