mod registry#

module registry#

Priority-sorted named registry.

SortedRegistry is 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 register or deregister call re-sorts immediately, so sorted_values is a read-only lookup.

Priority ordering

Entries are sorted in ascending priority order (lower numbers run first). This means a guardrail with priority 1 executes before one with priority 10.

Uniqueness

Names must be unique within a registry. Attempting to register a duplicate name returns an error. Use deregister first 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

true when the registry contains name, otherwise false.

fn deregister(&mut self, name: &str) -> bool#

Deregister an entry by name.

Parameters

  • name: Name of the entry to remove.

Returns

true when an entry was removed and false when name was 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 under name, otherwise None.

fn new(priority_fn: fn (&T) -> i32) -> Self#

Create a new empty registry with the given priority extraction function.

The runtime calls priority_fn on 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 SortedRegistry with 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) when name is 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, otherwise None.

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 / deregister call.

Returns

A newly allocated Vec of shared references ordered from lowest priority to highest priority.