pub struct SortedRegistry<T> { /* private fields */ }Expand description
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§
Source§impl<T> SortedRegistry<T>
impl<T> SortedRegistry<T>
Sourcepub fn new(priority_fn: fn(&T) -> i32) -> Self
pub 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.
Sourcepub fn register(&mut self, name: String, entry: T) -> Result<(), String>
pub 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.
Sourcepub fn deregister(&mut self, name: &str) -> bool
pub fn deregister(&mut self, name: &str) -> bool
Sourcepub fn sorted_values(&self) -> Vec<&T>
pub 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.
Auto Trait Implementations§
impl<T> Freeze for SortedRegistry<T>
impl<T> RefUnwindSafe for SortedRegistry<T>where
T: RefUnwindSafe,
impl<T> Send for SortedRegistry<T>where
T: Send,
impl<T> Sync for SortedRegistry<T>where
T: Sync,
impl<T> Unpin for SortedRegistry<T>where
T: Unpin,
impl<T> UnsafeUnpin for SortedRegistry<T>
impl<T> UnwindSafe for SortedRegistry<T>where
T: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> FutureExt for T
impl<T> FutureExt for T
Source§fn with_context(self, otel_cx: Context) -> WithContext<Self>
fn with_context(self, otel_cx: Context) -> WithContext<Self>
Source§fn with_current_context(self) -> WithContext<Self>
fn with_current_context(self) -> WithContext<Self>
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a tonic::Request