use serde::{Deserialize, Serialize};
#[derive(Debug, Clone, PartialEq, Eq, Default, Serialize, Deserialize)]
#[cfg_attr(feature = "wasm", derive(tsify_next::Tsify))]
#[cfg_attr(feature = "wasm", tsify(into_wasm_abi, from_wasm_abi))]
pub enum LayoutSyncMode {
#[default]
Independent,
Broadcast,
Follow {
target: String,
},
Accept,
}
impl LayoutSyncMode {
#[must_use]
pub fn follow(target: impl Into<String>) -> Self {
Self::Follow {
target: target.into(),
}
}
#[must_use]
pub const fn is_broadcasting(&self) -> bool {
matches!(self, Self::Broadcast)
}
#[must_use]
pub const fn is_receiving(&self) -> bool {
matches!(self, Self::Follow { .. } | Self::Accept)
}
#[must_use]
pub const fn is_independent(&self) -> bool {
matches!(self, Self::Independent)
}
#[must_use]
pub fn follow_target(&self) -> Option<&str> {
match self {
Self::Follow { target } => Some(target),
_ => None,
}
}
}
#[cfg(test)]
#[path = "layout_tests.rs"]
mod tests;