Skip to main content

CellStateExt

Trait CellStateExt 

Source
pub trait CellStateExt {
Show 18 methods // Required methods fn new(config: CellConfig) -> Self; fn update_timestamp(&mut self); fn is_full(&self) -> bool; fn is_valid(&self) -> bool; fn add_member(&mut self, node_id: String) -> bool; fn remove_member(&mut self, node_id: &str) -> bool; fn set_leader(&mut self, node_id: String) -> Result<(), &'static str>; fn clear_leader(&mut self); fn add_capability(&mut self, capability: Capability); fn get_capabilities_by_type( &self, capability_type: CapabilityType, ) -> Vec<&Capability>; fn has_capability_type(&self, capability_type: CapabilityType) -> bool; fn assign_platoon(&mut self, platoon_id: String); fn leave_platoon(&mut self); fn merge(&mut self, other: &CellState); fn member_count(&self) -> usize; fn is_member(&self, node_id: &str) -> bool; fn is_leader(&self, node_id: &str) -> bool; fn get_id(&self) -> Option<&str>;
}

Required Methods§

Source

fn new(config: CellConfig) -> Self

Create a new cell state

Source

fn update_timestamp(&mut self)

Update the timestamp to current time

Source

fn is_full(&self) -> bool

Check if the cell is at capacity

Source

fn is_valid(&self) -> bool

Check if the cell meets minimum size

Source

fn add_member(&mut self, node_id: String) -> bool

Add a member to the cell (OR-Set add operation)

This implements an OR-Set CRDT where members can be added and removed. Concurrent add/remove operations are resolved by: Add wins over Remove.

Source

fn remove_member(&mut self, node_id: &str) -> bool

Remove a member from the cell (OR-Set remove operation)

Source

fn set_leader(&mut self, node_id: String) -> Result<(), &'static str>

Set the cell leader (LWW-Register operation)

This implements Last-Write-Wins semantics for leader election. The leader must be a current member of the cell.

Source

fn clear_leader(&mut self)

Clear the cell leader

Source

fn add_capability(&mut self, capability: Capability)

Add a capability to the cell (G-Set operation)

This implements a G-Set CRDT where capabilities can only be added. Capabilities are aggregated from all cell members.

Source

fn get_capabilities_by_type( &self, capability_type: CapabilityType, ) -> Vec<&Capability>

Get all capabilities of a specific type

Source

fn has_capability_type(&self, capability_type: CapabilityType) -> bool

Check if cell has a specific capability type

Source

fn assign_platoon(&mut self, platoon_id: String)

Assign cell to a platoon (LWW-Register operation)

Source

fn leave_platoon(&mut self)

Remove cell from platoon

Source

fn merge(&mut self, other: &CellState)

Merge with another cell state (CRDT merge)

Merges two cell states using CRDT semantics:

  • Members: Union (OR-Set merge)
  • Leader: Take newer timestamp (LWW-Register merge)
  • Capabilities: Union (G-Set merge)
Source

fn member_count(&self) -> usize

Get the count of members

Source

fn is_member(&self, node_id: &str) -> bool

Check if a node is a member

Source

fn is_leader(&self, node_id: &str) -> bool

Check if this node is the leader

Source

fn get_id(&self) -> Option<&str>

Get the cell ID (convenience method)

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§