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 cellsRequired Methods§
Sourcefn new(config: ZoneConfig) -> Self
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);Sourcefn add_cell(&mut self, cell_id: String) -> bool
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 presentSourcefn remove_cell(&mut self, cell_id: &str) -> bool
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.
Sourcefn set_coordinator(&mut self, coordinator_id: String, timestamp: u64) -> bool
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 coordinatortimestamp- Logical timestamp for conflict resolution
§Returns
true if assignment was applied, false if rejected due to older timestamp
Sourcefn remove_coordinator(&mut self, timestamp: u64) -> bool
fn remove_coordinator(&mut self, timestamp: u64) -> bool
Remove the zone coordinator (LWW-Register deletion)
Sourcefn add_capability(&mut self, capability: Capability)
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.
Sourcefn cell_count(&self) -> usize
fn cell_count(&self) -> usize
Get the number of cells in this zone
Sourcefn contains_cell(&self, cell_id: &str) -> bool
fn contains_cell(&self, cell_id: &str) -> bool
Check if a specific cell is a member of this zone
Sourcefn merge(&mut self, other: &ZoneState)
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
Sourcefn update_timestamp(&mut self)
fn update_timestamp(&mut self)
Update timestamp to current time
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.