use crate::errors::*;
use crate::mesh_topo::topology::*;
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct TopologyBool {
status: bool,
}
impl TopologyBool {
pub fn new(status: bool) -> Self {
TopologyBool { status }
}
pub fn set(&mut self, status: bool) {
self.status = status
}
pub fn get(&self) -> bool {
self.status
}
}
impl Topology for TopologyBool {
fn allowed(&self, _from: usize, _to: usize) -> Result<bool> {
Ok(self.status)
}
}
impl From<bool> for TopologyBool {
fn from(status: bool) -> TopologyBool {
TopologyBool::new(status)
}
}
impl From<TopologyBool> for bool {
fn from(topo: TopologyBool) -> bool {
topo.get()
}
}
#[cfg(test)]
mod tests {
#[test]
#[cfg(feature = "serde")]
fn test_serde() {
use super::*;
let topology = TopologyBool::new(true);
let json = serde_json::to_string(&topology).unwrap();
let deserialized: TopologyBool = serde_json::from_str(&json).unwrap();
assert_eq!(topology.get(), deserialized.get());
}
}