use std::ops::{Deref, DerefMut};
use disposition_model_common::Map;
use serde::{Deserialize, Serialize};
use crate::{layout::NodeLayout, node::NodeId};
#[cfg_attr(feature = "openapi", derive(utoipa::ToSchema))]
#[derive(Clone, Debug, Default, PartialEq, Eq, Deserialize, Serialize)]
pub struct NodeLayouts(Map<NodeId, NodeLayout>);
impl NodeLayouts {
pub fn new() -> Self {
Self::default()
}
pub fn with_capacity(capacity: usize) -> Self {
Self(Map::with_capacity(capacity))
}
pub fn into_inner(self) -> Map<NodeId, NodeLayout> {
self.0
}
pub fn is_empty(&self) -> bool {
self.0.is_empty()
}
}
impl Deref for NodeLayouts {
type Target = Map<NodeId, NodeLayout>;
fn deref(&self) -> &Self::Target {
&self.0
}
}
impl DerefMut for NodeLayouts {
fn deref_mut(&mut self) -> &mut Self::Target {
&mut self.0
}
}
impl From<Map<NodeId, NodeLayout>> for NodeLayouts {
fn from(inner: Map<NodeId, NodeLayout>) -> Self {
Self(inner)
}
}
impl FromIterator<(NodeId, NodeLayout)> for NodeLayouts {
fn from_iter<I: IntoIterator<Item = (NodeId, NodeLayout)>>(iter: I) -> Self {
Self(Map::from_iter(iter))
}
}