pub struct CellId<S> { /* private fields */ }Expand description
A typed identifier for a cell holding values of type S.
The type parameter ensures compile-time safety: you cannot
accidentally use a CellId<i32> where a CellId<String> is
expected. At runtime, cells are stored in a type-erased container,
but the API maintains type safety through these phantom-typed
identifiers.
§Type Erasure Pattern
Propagator networks need to store cells with heterogeneous types
(e.g., Cell<Max<i32>>, Cell<HashSet<String>>, etc.) in the
same container. This is accomplished through a two-layer type
system:
- Storage layer (runtime): Cells stored as
Box<dyn Any>(type-erased) - API layer (compile-time):
CellId<S>carries the type information
When you access a cell via its CellId<S>, the network can safely
downcast the type-erased storage back to the concrete type
Cell<S>.
§Example
use postbox::propagator::CellId;
use postbox::lattice::Max;
use std::collections::HashSet;
// Each cell ID carries its type
let id1: CellId<Max<i32>> = CellId::new(0);
let id2: CellId<Max<i32>> = CellId::new(1);
let id3: CellId<HashSet<String>> = CellId::new(0);
// Can compare IDs of the same type
assert_ne!(id1, id2);
assert_eq!(id1.raw(), 0);
assert_eq!(id2.raw(), 1);
// But CellId<Max<i32>> and CellId<HashSet<String>> are different types
// (this would be a compile error):
// assert_ne!(id1, id3); // ← error: mismatched typesImplementations§
Source§impl<S> CellId<S>
impl<S> CellId<S>
Sourcepub fn new(id: usize) -> Self
pub fn new(id: usize) -> Self
Create a new cell ID from a raw integer.
This is typically called internally by the network when
creating cells. The type parameter S captures what semigroup
type this cell holds.
§Example
use postbox::propagator::CellId;
use postbox::lattice::Max;
let id: CellId<Max<i32>> = CellId::new(42);
assert_eq!(id.raw(), 42);