mod registry#
- module registry#
Priority-sorted named registry.
SortedRegistryis the backbone data structure for all guardrail and intercept registries in the NeMo Flow runtime. It stores entries by unique name and provides iteration in ascending priority order, with eager re-sorting on every mutation.Structs and Unions
- struct SortedRegistry<T>#
A named registry that maintains a sorted order by priority.
Items are stored by unique string name and sorted by an integer priority extracted via a caller-provided function. The sort is performed eagerly: every
registerorderegistercall re-sorts immediately, sosorted_valuesis a read-only lookup.Priority ordering
Entries are sorted in ascending priority order (lower numbers run first). This means a guardrail with priority
1executes before one with priority10.Uniqueness
Names must be unique within a registry. Attempting to
registera duplicate name returns an error. Usederegisterfirst to remove an existing entry before re-registering.Implementations
- impl<T> SortedRegistry<T>#
Functions
- fn contains(&self, name: &str) -> bool#
Report whether an entry with the given name exists.
Parameters
name: Name to test for membership.
Returns
truewhen the registry containsname, otherwisefalse.
- fn deregister(&mut self, name: &str) -> bool#
Deregister an entry by name.
Parameters
name: Name of the entry to remove.
Returns
truewhen an entry was removed andfalsewhennamewas not present.Notes
Successful removal eagerly re-sorts the cached priority order.
- fn get(&self, name: &str) -> Option<&T>#
Return a shared reference to an entry by name.
Parameters
name: Name of the entry to resolve.
Returns
Some(&T)when an entry exists undername, otherwiseNone.
- fn new(priority_fn: fn (&T) -> i32) -> Self#
Create a new empty registry with the given priority extraction function.
The runtime calls
priority_fnon each stored entry to determine its sort key. Lower values are ordered first.Parameters
priority_fn: Function used to extract the integer priority from a stored entry.
Returns
A new empty
SortedRegistrywith no entries.
- fn register(&mut self, name: String, entry: T) -> Result<(), String>#
Register a new entry under a unique name.
Parameters
name: Unique name used to address the entry later.entry: Value to store in the registry.
Returns
Ok(())when the entry was inserted.Errors
Returns
Err(String)whennameis already present in the registry.Notes
Successful registration eagerly re-sorts the cached priority order.
- fn remove(&mut self, name: &str) -> Option<T>#
Remove and return an entry by name.
Parameters
name: Name of the entry to remove.
Returns
Some(T)when an entry was removed, otherwiseNone.Notes
Successful removal eagerly re-sorts the cached priority order.
- fn sorted_values(&self) -> Vec<&T>#
Return entries sorted by priority (ascending).
This is a read-only operation — the sort order is maintained eagerly on every
register/deregistercall.Returns
A newly allocated
Vecof shared references ordered from lowest priority to highest priority.