use super::FrameId;
use serde::Serialize;
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize)]
pub struct StackId(pub u32);
#[derive(Debug, Clone, Serialize)]
pub struct Stack {
pub id: StackId,
pub frames: Vec<FrameId>,
}
impl Stack {
pub fn new(id: StackId, frames: Vec<FrameId>) -> Self {
Self { id, frames }
}
pub fn leaf(&self) -> Option<FrameId> {
self.frames.last().copied()
}
pub fn root(&self) -> Option<FrameId> {
self.frames.first().copied()
}
pub fn contains(&self, frame: FrameId) -> bool {
self.frames.contains(&frame)
}
pub fn depth(&self) -> usize {
self.frames.len()
}
pub fn is_empty(&self) -> bool {
self.frames.is_empty()
}
}