swactor/crates/process/src/subscriber.rs
Zachery Aaron Shores-Chmielewski e15678bddb feat: native process manager
Enable swactor to spawn and manage native processes using ssh.
2026-02-23 11:44:15 +07:00

41 lines
933 B
Rust

use swactor::actor::ActorAddress;
/// A deduplicated collection of subscriber addresses.
#[derive(Debug, Clone)]
pub struct SubscriberSet {
inner: Vec<ActorAddress>,
}
impl SubscriberSet {
pub fn new() -> Self {
Self { inner: Vec::new() }
}
/// Add an address. No-op if already present.
pub fn add(&mut self, address: ActorAddress) {
if !self.inner.contains(&address) {
self.inner.push(address);
}
}
/// Remove an address. No-op if not present.
pub fn remove(&mut self, address: &ActorAddress) {
self.inner.retain(|a| a != address);
}
/// Snapshot of current subscribers.
pub fn snapshot(&self) -> Vec<ActorAddress> {
self.inner.clone()
}
/// Number of subscribers.
pub fn count(&self) -> usize {
self.inner.len()
}
}
impl Default for SubscriberSet {
fn default() -> Self {
Self::new()
}
}