Skip to main content

ChannelStore

Struct ChannelStore 

Source
pub struct ChannelStore { /* private fields */ }
Expand description

Heterogeneous typed channel map.

Stores type-erased Channel values indexed by TypeId. Uses a two-level lookup: TypeId → ChannelId (usize) → Channel.

§Example

use pe_core::channel::{LastValue, Appender};
use pe_core::channel_store::ChannelStore;

let mut store = ChannelStore::new();
store.insert::<LastValue<String>>(LastValue::new("hello".into()));
store.insert::<Appender<i32>>(Appender::new());

let val = store.get::<LastValue<String>>().unwrap();
assert_eq!(val.get(), "hello");

Implementations§

Source§

impl ChannelStore

Source

pub fn new() -> Self

Create an empty channel store.

Source

pub fn insert<T: Channel + 'static>(&mut self, channel: T)

Insert a channel by its concrete type. Overwrites any existing channel of the same type.

Source

pub fn get<T: Channel + 'static>(&self) -> Option<&T>

Get an immutable reference to a channel by its concrete type.

Source

pub fn get_mut<T: Channel + 'static>(&mut self) -> Option<&mut T>

Get a mutable reference to a channel by its concrete type.

Source

pub fn get_by_id(&self, id: ChannelId) -> Option<&dyn Channel>

Get a channel by ChannelId (fast path, no hashing).

Source

pub fn get_by_id_mut(&mut self, id: ChannelId) -> Option<&mut dyn Channel>

Get a mutable channel by ChannelId (fast path, no hashing).

Source

pub fn id_of<T: 'static>(&self) -> Option<ChannelId>

Look up the ChannelId for a type. Use this once, then use get_by_id for repeated fast access.

Source

pub fn clear_ephemeral(&mut self)

Clear all ephemeral and topic channels (called between supersteps).

§REVIEW(002): Selective clearing via is_ephemeral()

Only calls clear() on channels that opt in via is_ephemeral() == true. Previously called clear() on ALL channels, relying on persistent channels having no-op impls. The new approach is explicit and won’t break if a future Channel type has a meaningful clear() that shouldn’t run between supersteps.

Source

pub fn snapshot(&self) -> ChannelStore

Create a snapshot (deep clone) for snapshot isolation during parallel execution. Each channel is cloned via clone_box().

Source

pub fn len(&self) -> usize

Number of channels in the store.

Source

pub fn is_empty(&self) -> bool

Whether the store is empty.

Trait Implementations§

Source§

impl Default for ChannelStore

Source§

fn default() -> Self

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.

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.