Skip to main content

CellMap

Struct CellMap 

Source
pub struct CellMap<K, V, M = CellMutable>
where K: Hash + Eq + CellValue, V: CellValue,
{ /* private fields */ }
Expand description

A reactive HashMap with per-key observability.

§Example

use hyphae::{CellMap, Gettable, Watchable, Signal};

let map = CellMap::<String, i32>::new();

// Observe a specific key
let value_cell = map.get(&"counter".to_string());
assert_eq!(value_cell.get(), None);

// Insert triggers update
map.insert("counter".to_string(), 42);
assert_eq!(value_cell.get(), Some(42));

// Observe all entries
let entries = map.entries();
assert_eq!(entries.get().len(), 1);

Implementations§

Source§

impl<K, V> CellMap<K, V, CellMutable>
where K: Hash + Eq + CellValue, V: CellValue,

Source

pub fn new() -> Self

Create a new empty CellMap.

Source

pub fn own(&self, guard: SubscriptionGuard)

Own a subscription guard, keeping it alive as long as this CellMap exists.

Source

pub fn own_guard(&self, guard: SubscriptionGuard)

Own a subscription guard, keeping it alive as long as this CellMap exists.

This enables building custom reactive CellMaps driven by external cells.

Source

pub fn insert(&self, key: K, value: V) -> Option<V>

Insert a key-value pair, returning the old value if present.

Source

pub fn insert_many(&self, entries: Vec<(K, V)>)

Insert multiple key-value pairs and emit a single batch diff.

Source

pub fn remove(&self, key: &K) -> Option<V>

Remove a key, returning the old value if present.

Source

pub fn remove_many(&self, keys: Vec<K>)

Remove multiple keys and emit a single batch diff.

Source

pub fn replace_all(&self, entries: Vec<(K, V)>)

Replace all entries atomically, emitting a single Batch diff.

Removes keys not in entries, inserts/updates keys that are. Skips no-op updates (existing key with equal value). Emits MapDiff::Batch with the actual changes so downstream subscribers see one atomic replacement instead of N individual diffs.

Source

pub fn apply_batch(&self, changes: Vec<MapDiff<K, V>>)

Apply a batch of diffs and emit them as one MapDiff::Batch.

Source

pub fn with_name(self, name: impl Into<Arc<str>>) -> Self

Give this CellMap a name for debugging. Names its internal cells accordingly.

Source

pub fn lock(self) -> CellMap<K, V, CellImmutable>

Lock the map to prevent further mutations.

Source§

impl<K, V, M> CellMap<K, V, M>
where K: Hash + Eq + CellValue, V: CellValue,

Source

pub fn downgrade(&self) -> WeakCellMap<K, V>

Create a weak handle to this map.

Source

pub fn get(&self, key: &K) -> Cell<Option<V>, CellImmutable>

Get an observable Cell for a specific key.

Returns a Cell<Option<V>> that updates whenever the key’s value changes. Multiple calls with the same key return the same underlying Cell.

Source

pub fn entries(&self) -> Cell<Vec<(K, V)>, CellImmutable>

Get an observable Cell of all entries.

Returns a derived cell that maintains entries incrementally via diffs. The initial value is computed from the current map state, then updates are applied incrementally as O(1) operations per diff.

Source

pub fn items(&self) -> Cell<Vec<V>, CellImmutable>

Get an observable Cell of all values.

This maintains its own diff-driven projection to avoid forcing an intermediate entries materialization on hot value-only paths.

Source

pub fn keys(&self) -> Cell<Vec<K>, CellImmutable>

Get an observable Cell of all keys.

Source

pub fn size(&self) -> Cell<usize, CellImmutable>

Get an observable Cell of the map size.

This is the preferred reactive count operator because it reuses the internally maintained length cell instead of materializing entries.

Source

pub fn len(&self) -> Cell<usize, CellImmutable>

Get an observable Cell of the map length.

Alias for CellMap::size.

Source

pub fn is_empty(&self) -> bool

Check if map is empty (non-reactive).

Source

pub fn diffs(&self) -> Cell<MapDiff<K, V>, CellImmutable>

Get an observable Cell of diff notifications.

Emits MapDiff updates. Starts with MapDiff::Initial { entries: vec![] }.

Source

pub fn snapshot(&self) -> Vec<(K, V)>

Get a point-in-time snapshot of all entries (non-reactive).

Unlike entries(), this does NOT create a Cell or subscribe to changes. Use this for one-shot reads where you don’t need live updates.

Source

pub fn contains_key(&self, key: &K) -> bool

Check if key exists (non-reactive).

Source

pub fn get_value(&self, key: &K) -> Option<V>

Get current value for key (non-reactive).

Source

pub fn subscribe_diffs<F>(&self, callback: F) -> SubscriptionGuard
where F: Fn(&MapDiff<K, V>) + Send + Sync + 'static,

Subscribe to diffs with an initial snapshot.

The callback is first called with MapDiff::Initial containing all current entries, then called with subsequent diffs as the map changes.

Returns a guard that cancels the subscription when dropped.

Source§

impl<K, V, M> CellMap<K, V, M>
where K: Hash + Eq + CellValue, V: CellValue, M: Send + Sync + 'static,

Source

pub fn nest<PK>( &self, fk: impl Fn(&V) -> PK + Send + Sync + 'static, ) -> NestedMap<PK, K, V>
where PK: Hash + Eq + CellValue,

Create a grouped view of this map, partitioned by a foreign-key extractor.

The returned NestedMap observes this CellMap reactively and maintains a live FK index. It implements ReactiveKeys and ReactiveMap, so it composes with joins exactly like a CellMap.

let orders: CellMap<OrderId, Order> = CellMap::new();
let nested = orders.nest(|order| order.customer_id.clone());
// nested: NestedMap<CustomerId, OrderId, Order>

Trait Implementations§

Source§

impl<K, V, M: Clone> Clone for CellMap<K, V, M>
where K: Hash + Eq + CellValue + Clone, V: CellValue + Clone,

Source§

fn clone(&self) -> CellMap<K, V, M>

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<K, V> Default for CellMap<K, V, CellMutable>
where K: Hash + Eq + CellValue, V: CellValue,

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl<K, V, M> MapQuery<K, V> for CellMap<K, V, M>
where K: CellValue + Hash + Eq, V: CellValue, M: Clone + Send + Sync + 'static,

Source§

fn materialize(self) -> CellMap<K, V, CellImmutable>

No-op materialize: the cell map is already a cached, multicast source. Just flip the marker to CellImmutable and reuse the same Arc<inner>.

Source§

impl<K, V, M> ReactiveKeys for CellMap<K, V, M>
where K: Hash + Eq + CellValue, V: CellValue, M: Send + Sync + 'static,

Source§

type Key = K

Source§

fn key_set(&self) -> Vec<K>

Snapshot of all current keys. Non-reactive, point-in-time.
Source§

fn contains_key(&self, key: &K) -> bool

Does key currently exist? Non-reactive, point-in-time.
Source§

fn subscribe_keys( &self, cb: impl Fn(&KeyChange<K>) + Send + Sync + 'static, ) -> SubscriptionGuard

Subscribe to key-set changes. Read more
Source§

impl<K, V, M> ReactiveMap for CellMap<K, V, M>
where K: Hash + Eq + CellValue, V: CellValue, M: Send + Sync + 'static,

Source§

type Value = V

Source§

fn get_value(&self, key: &K) -> Option<V>

Point-in-time value lookup by key.
Source§

fn snapshot(&self) -> Vec<(K, V)>

Point-in-time snapshot of all entries.
Source§

fn subscribe_diffs_reactive( &self, cb: impl Fn(&MapDiff<K, V>) + Send + Sync + 'static, ) -> SubscriptionGuard

Subscribe to diffs with an initial snapshot. Read more

Auto Trait Implementations§

§

impl<K, V, M> Freeze for CellMap<K, V, M>

§

impl<K, V, M = CellMutable> !RefUnwindSafe for CellMap<K, V, M>

§

impl<K, V, M> Send for CellMap<K, V, M>
where M: Send,

§

impl<K, V, M> Sync for CellMap<K, V, M>
where M: Sync,

§

impl<K, V, M> Unpin for CellMap<K, V, M>
where M: Unpin,

§

impl<K, V, M> UnsafeUnpin for CellMap<K, V, M>

§

impl<K, V, M = CellMutable> !UnwindSafe for CellMap<K, V, M>

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<K, V, M> CountByExt<K, V> for M
where K: Hash + Eq + CellValue, V: CellValue, M: MapQuery<K, V>,

Source§

fn count_by<GK, F>(self, group_key: F) -> CountByPlan<Self, K, V, GK, F>
where GK: Hash + Eq + CellValue, F: Fn(&K, &V) -> GK + Send + Sync + 'static,

Groups rows by group_key(&source_key, &source_value) and stores how many rows are in each group. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<K, V, M> GroupByExt<K, V> for M
where K: Hash + Eq + CellValue, V: CellValue, M: MapQuery<K, V>,

Source§

fn group_by<GK, F>(self, group_key: F) -> GroupByPlan<Self, K, V, GK, F>
where K: Ord, GK: Hash + Eq + CellValue, F: Fn(&K, &V) -> GK + Send + Sync + 'static,

Groups source rows by group_key(&source_key, &source_value). Read more
Source§

impl<K, V, M> InnerJoinExt<K, V> for M
where K: Hash + Eq + CellValue, V: CellValue, M: MapQuery<K, V>,

Source§

fn inner_join<R, RV>(self, right: R) -> InnerJoinByKeyPlan<Self, R, K, V, RV>
where R: MapQuery<K, RV>, RV: CellValue,

Inner join on equal map keys. Read more
Source§

fn inner_join_fk<R, RK, RV>( self, right: R, ) -> InnerJoinByPairPlan<Self, R, K, V, RK, RV, K, impl Fn(&K, &V) -> K + Send + Sync + 'static, impl Fn(&RK, &RV) -> K + Send + Sync + 'static>
where R: MapQuery<RK, RV>, RK: Hash + Eq + CellValue, RV: CellValue + HasForeignKey<V>, <<RV as HasForeignKey<V>>::ForeignKey as IdFor<V>>::MapKey: Into<K>,

Inner join using foreign key relationship. Read more
Source§

fn inner_join_by<R, RK, RV, JK, FL, FR>( self, right: R, left_key: FL, right_key: FR, ) -> InnerJoinByPairPlan<Self, R, K, V, RK, RV, JK, FL, FR>
where R: MapQuery<RK, RV>, RK: Hash + Eq + CellValue, RV: CellValue, JK: Hash + Eq + CellValue, FL: Fn(&K, &V) -> JK + Send + Sync + 'static, FR: Fn(&RK, &RV) -> JK + Send + Sync + 'static,

Inner join using explicit key extractors. Read more
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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> JoinKeyFrom<T> for T
where T: Clone,

Source§

fn join_key_from(value: &T) -> T

Source§

impl<K, V, M> LeftJoinExt<K, V> for M
where K: Hash + Eq + CellValue, V: CellValue, M: MapQuery<K, V>,

Source§

fn left_join<R, RV>( self, right: R, ) -> LeftJoinPlan<Self, R, K, V, K, RV, K, impl Fn(&K, &V) -> K + Send + Sync + 'static, impl Fn(&K, &RV) -> K + Send + Sync + 'static>
where R: MapQuery<K, RV>, RV: CellValue,

Left join on equal map keys. Read more
Source§

fn left_join_fk<R, RK, RV>( self, right: R, ) -> LeftJoinPlan<Self, R, K, V, RK, RV, K, impl Fn(&K, &V) -> K + Send + Sync + 'static, impl Fn(&RK, &RV) -> K + Send + Sync + 'static>
where R: MapQuery<RK, RV>, RK: Hash + Eq + CellValue, RV: CellValue + HasForeignKey<V>, <<RV as HasForeignKey<V>>::ForeignKey as IdFor<V>>::MapKey: Into<K>,

Left join using foreign key relationship. Read more
Source§

fn left_join_by<R, RK, RV, JK, FL, FR>( self, right: R, left_key: FL, right_key: FR, ) -> LeftJoinPlan<Self, R, K, V, RK, RV, JK, FL, FR>
where R: MapQuery<RK, RV>, RK: Hash + Eq + CellValue, RV: CellValue, JK: Hash + Eq + CellValue, FL: Fn(&K, &V) -> JK + Send + Sync + 'static, FR: Fn(&RK, &RV) -> JK + Send + Sync + 'static,

Left join using explicit key extractors. Read more
Source§

impl<K, V, M> LeftSemiJoinExt<K, V> for M
where K: Hash + Eq + CellValue, V: CellValue, M: MapQuery<K, V>,

Source§

fn left_semi_join<R, RV>( self, right: R, ) -> LeftSemiJoinPlan<Self, R, K, V, K, RV, K, impl Fn(&K, &V) -> K + Send + Sync + 'static, impl Fn(&K, &RV) -> K + Send + Sync + 'static>
where R: MapQuery<K, RV>, RV: CellValue,

Left semi join on equal map keys. Read more
Source§

fn left_semi_join_fk<R, RK, RV>( self, right: R, ) -> LeftSemiJoinPlan<Self, R, K, V, RK, RV, K, impl Fn(&K, &V) -> K + Send + Sync + 'static, impl Fn(&RK, &RV) -> K + Send + Sync + 'static>
where R: MapQuery<RK, RV>, RK: Hash + Eq + CellValue, RV: CellValue + HasForeignKey<V>, <<RV as HasForeignKey<V>>::ForeignKey as IdFor<V>>::MapKey: Into<K>,

Left semi join using foreign key relationship. Read more
Source§

fn left_semi_join_by<R, RK, RV, JK, FL, FR>( self, right: R, left_key: FL, right_key: FR, ) -> LeftSemiJoinPlan<Self, R, K, V, RK, RV, JK, FL, FR>
where R: MapQuery<RK, RV>, RK: Hash + Eq + CellValue, RV: CellValue, JK: Hash + Eq + CellValue, FL: Fn(&K, &V) -> JK + Send + Sync + 'static, FR: Fn(&RK, &RV) -> JK + Send + Sync + 'static,

Left semi join using explicit key extractors. Read more
Source§

impl<K, V, Q> MapQueryShareExt<K, V> for Q
where K: CellValue + Hash + Eq, V: CellValue, Q: MapQuery<K, V>,

Source§

fn share(self) -> SharedMapQuery<K, V>

Convert this map query into a Clone-able multicast handle.
Source§

impl<K, V, M> MultiLeftJoinExt<K, V> for M
where K: Hash + Eq + CellValue, V: CellValue, M: MapQuery<K, V>,

Source§

fn multi_left_join_by<R, RK, RV, JK, FL, FR>( self, right: R, left_keys: FL, right_key: FR, ) -> MultiLeftJoinPlan<Self, R, K, V, RK, RV, JK, FL, FR>
where R: MapQuery<RK, RV>, RK: Hash + Eq + CellValue, RV: CellValue, JK: Hash + Eq + CellValue, FL: Fn(&K, &V) -> Vec<JK> + Send + Sync + 'static, FR: Fn(&RK, &RV) -> JK + Send + Sync + 'static,

Left join where each left item maps to multiple join keys. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<K, V, M> ProjectCellExt<K, V> for M
where K: Hash + Eq + CellValue, V: CellValue, M: MapQuery<K, V>,

Source§

fn project_cell<K2, V2, W, F>( self, mapper: F, ) -> ProjectCellPlan<Self, K, V, K2, V2, W, F>
where K2: Hash + Eq + CellValue, V2: CellValue, W: Watchable<Option<(K2, V2)>> + Gettable<Option<(K2, V2)>> + Clone + Send + Sync + 'static, F: Fn(&K, &V) -> W + Send + Sync + 'static,

Reactive project variant: each row maps to a watchable optional output row. Read more
Source§

impl<K, V, M> ProjectManyExt<K, V> for M
where K: Hash + Eq + CellValue, V: CellValue, M: MapQuery<K, V>,

Source§

fn project_many<K2, V2, F>(self, f: F) -> ProjectManyPlan<Self, K, V, K2, V2, F>
where K2: Hash + Eq + CellValue, V2: CellValue, F: Fn(&K, &V) -> Vec<(K2, V2)> + Send + Sync + 'static,

Projects each source row to zero, one, or many output rows. Read more
Source§

impl<K, V, M> ProjectMapExt<K, V> for M
where K: Hash + Eq + CellValue, V: CellValue, M: MapQuery<K, V>,

Source§

fn project<K2, V2, F>(self, f: F) -> ProjectPlan<Self, K, V, K2, V2, F>
where K2: Hash + Eq + CellValue, V2: CellValue, F: Fn(&K, &V) -> Option<(K2, V2)> + Send + Sync + 'static,

Projects each source row to at most one output row. Read more
Source§

impl<K, V, M> SelectCellExt<K, V> for M
where K: Hash + Eq + CellValue, V: CellValue, M: MapQuery<K, V>,

Source§

fn select_cell<W, F>(self, predicate: F) -> SelectCellPlan<Self, K, V, W, F>
where W: Pipeline<bool> + PipelineSeed<bool> + Gettable<bool> + Clone + Send + Sync + 'static, F: Fn(&K, &V) -> W + Send + Sync + 'static,

Reactive filter: each row has a watchable boolean gate. Read more
Source§

impl<K, V, M> SelectExt<K, V> for M
where K: Hash + Eq + CellValue, V: CellValue, M: MapQuery<K, V>,

Source§

fn select<F>(self, predicate: F) -> SelectPlan<Self, K, V, F>
where F: Fn(&V) -> bool + Send + Sync + 'static,

Filters rows by value. Read more
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.