CellId

Struct CellId 

Source
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 types

Implementations§

Source§

impl<S> CellId<S>

Source

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);
Source

pub fn raw(&self) -> usize

Get the raw ID.

This returns the underlying integer identifier, discarding type information. Useful for indexing into type-erased storage.

§Example
use postbox::propagator::CellId;

let id: CellId<String> = CellId::new(7);
assert_eq!(id.raw(), 7);

Trait Implementations§

Source§

impl<S> Clone for CellId<S>

Source§

fn clone(&self) -> Self

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<S: Debug> Debug for CellId<S>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<S: Hash> Hash for CellId<S>

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl<S: PartialEq> PartialEq for CellId<S>

Source§

fn eq(&self, other: &CellId<S>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<S> Copy for CellId<S>

Source§

impl<S: Eq> Eq for CellId<S>

Source§

impl<S> StructuralPartialEq for CellId<S>

Auto Trait Implementations§

§

impl<S> Freeze for CellId<S>

§

impl<S> RefUnwindSafe for CellId<S>
where S: RefUnwindSafe,

§

impl<S> Send for CellId<S>
where S: Send,

§

impl<S> Sync for CellId<S>
where S: Sync,

§

impl<S> Unpin for CellId<S>
where S: Unpin,

§

impl<S> UnwindSafe for CellId<S>
where S: UnwindSafe,

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<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> 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.