Skip to main content

ZoneStateExt

Trait ZoneStateExt 

Source
pub trait ZoneStateExt {
Show 13 methods // Required methods fn new(config: ZoneConfig) -> Self; fn add_cell(&mut self, cell_id: String) -> bool; fn remove_cell(&mut self, cell_id: &str) -> bool; fn set_coordinator( &mut self, coordinator_id: String, timestamp: u64, ) -> bool; fn remove_coordinator(&mut self, timestamp: u64) -> bool; fn add_capability(&mut self, capability: Capability); fn is_valid(&self) -> bool; fn is_full(&self) -> bool; fn cell_count(&self) -> usize; fn contains_cell(&self, cell_id: &str) -> bool; fn merge(&mut self, other: &ZoneState); fn update_timestamp(&mut self); fn stats(&self) -> ZoneStats;
}
Expand description

Extension trait for ZoneState with CRDT operations

Uses multiple CRDT types for distributed consistency:

  • Commander: LWW-Register (Last-Write-Wins)
  • Cells: OR-Set (Observed-Remove Set)
  • Capabilities: G-Set (Grow-only Set)

§Example

use peat_protocol::models::zone::{ZoneConfig, ZoneConfigExt, ZoneState, ZoneStateExt};

let config = ZoneConfig::new("zone_1".to_string(), 10);
let mut zone = ZoneState::new(config);

// Add cells to zone
zone.add_cell("cell_alpha".to_string());
zone.add_cell("cell_beta".to_string());

assert_eq!(zone.cell_count(), 2);
assert!(zone.is_valid()); // Meets minimum cells

Required Methods§

Source

fn new(config: ZoneConfig) -> Self

Create a new zone state from configuration

§Example
use peat_protocol::models::zone::{ZoneConfig, ZoneConfigExt, ZoneState, ZoneStateExt};

let config = ZoneConfig::new("zone_north".to_string(), 5);
let zone = ZoneState::new(config);
Source

fn add_cell(&mut self, cell_id: String) -> bool

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

Returns true if cell was added, false if already present or zone is full.

§Example
use peat_protocol::models::zone::{ZoneConfig, ZoneConfigExt, ZoneState, ZoneStateExt};

let config = ZoneConfig::new("zone_1".to_string(), 3);
let mut zone = ZoneState::new(config);

assert!(zone.add_cell("cell_1".to_string()));
assert!(!zone.add_cell("cell_1".to_string())); // Already present
Source

fn remove_cell(&mut self, cell_id: &str) -> bool

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

Returns true if cell was removed, false if not present.

Source

fn set_coordinator(&mut self, coordinator_id: String, timestamp: u64) -> bool

Set the zone coordinator (LWW-Register operation)

The coordinator must be a leader of a cell within this zone.

§Arguments
  • coordinator_id - Node ID of the coordinator
  • timestamp - Logical timestamp for conflict resolution
§Returns

true if assignment was applied, false if rejected due to older timestamp

Source

fn remove_coordinator(&mut self, timestamp: u64) -> bool

Remove the zone coordinator (LWW-Register deletion)

Source

fn add_capability(&mut self, capability: Capability)

Add an aggregated capability (G-Set add operation)

Capabilities are grow-only - once added, they cannot be removed.

Source

fn is_valid(&self) -> bool

Check if zone meets minimum cell requirement

Source

fn is_full(&self) -> bool

Check if zone is at maximum capacity

Source

fn cell_count(&self) -> usize

Get the number of cells in this zone

Source

fn contains_cell(&self, cell_id: &str) -> bool

Check if a specific cell is a member of this zone

Source

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

Merge another zone state into this one (CRDT merge)

Applies CRDT semantics for each component:

  • Coordinator: LWW based on timestamp
  • Cells: OR-Set union
  • Capabilities: G-Set union
§Panics

Panics if attempting to merge zones with different IDs

Source

fn update_timestamp(&mut self)

Update timestamp to current time

Source

fn stats(&self) -> ZoneStats

Get zone statistics

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§