pub struct SourceRegistry { /* private fields */ }Expand description
Maps natural domain keys to DataSource values.
Single World resource supporting any number of key types via
type erasure. Each key type K gets its own internal
HashMap<K, DataSource>. The TypeId dispatch is one hash
lookup to find the right inner map — cold path only.
Any Hash + Eq + Send + 'static type works as a key — no trait
to implement, no macro to invoke. Newtypes, enums, and tuples
all work out of the box.
§Example
ⓘ
// Setup
let src = notify.register_source();
registry.insert(InstrumentId("BTC"), src);
// Runtime lookup (cold path — from event handler)
let src = registry.get(&InstrumentId("BTC")).unwrap();
notify.register(|t| ctx, step, reg).subscribe(src);
// Hot path — DataSource pre-resolved, no registry involvement
notify.mark(src);Implementations§
Source§impl SourceRegistry
impl SourceRegistry
Sourcepub fn insert<K: Hash + Eq + Send + 'static>(
&mut self,
key: K,
source: DataSource,
)
pub fn insert<K: Hash + Eq + Send + 'static>( &mut self, key: K, source: DataSource, )
Map a typed key to a DataSource.
Overwrites any previous mapping for this key.
Sourcepub fn get<K: Hash + Eq + Send + 'static>(&self, key: &K) -> Option<DataSource>
pub fn get<K: Hash + Eq + Send + 'static>(&self, key: &K) -> Option<DataSource>
Look up a DataSource by typed key.
Returns None if the key is not registered.
Sourcepub fn remove<K: Hash + Eq + Send + 'static>(
&mut self,
key: &K,
) -> Option<DataSource>
pub fn remove<K: Hash + Eq + Send + 'static>( &mut self, key: &K, ) -> Option<DataSource>
Remove a key mapping. Returns the DataSource so the caller
can also call ReactorNotify::remove_source to free the slot.
Trait Implementations§
Source§impl Default for SourceRegistry
impl Default for SourceRegistry
Source§fn default() -> SourceRegistry
fn default() -> SourceRegistry
Returns the “default value” for a type. Read more
impl Resource for SourceRegistry
Auto Trait Implementations§
impl Freeze for SourceRegistry
impl !RefUnwindSafe for SourceRegistry
impl Send for SourceRegistry
impl !Sync for SourceRegistry
impl Unpin for SourceRegistry
impl UnsafeUnpin for SourceRegistry
impl !UnwindSafe for SourceRegistry
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
Mutably borrows from an owned value. Read more