extern crate alloc;
use alloc::collections::BTreeMap;
use crate::kairos::{Clock, TickCounter};
use crate::metis::{Composer, Dot, DotFun, DotMap, Purview, Rhapsody};
mod cursor;
mod gossip;
mod text;
pub use gossip::{gossip_cursors, gossip_text};
pub type TextComposer = Composer<Rhapsody>;
pub type CursorStore = DotMap<u32, DotFun<u64>>;
pub type CursorComposer = Composer<CursorStore>;
pub struct Replica {
station: u32,
chars: BTreeMap<Dot, char>,
text: TextComposer,
cursors: CursorComposer,
clock: Clock<TickCounter>,
purview: Purview,
}
impl Replica {
#[must_use]
pub fn new(station: u32, roster: &[u32]) -> Self {
let clock = Clock::with_default_config(TickCounter::new(), station).unwrap();
Self {
station,
chars: BTreeMap::new(),
text: Composer::new(station),
cursors: Composer::new(station),
clock,
purview: Purview::new(roster.iter().copied()),
}
}
#[must_use]
pub const fn station(&self) -> u32 {
self.station
}
#[must_use]
pub const fn chars(&self) -> &BTreeMap<Dot, char> {
&self.chars
}
}