profile_inspect/ir/
stack.rs1use super::FrameId;
2use serde::Serialize;
3
4#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize)]
6pub struct StackId(pub u32);
7
8#[derive(Debug, Clone, Serialize)]
13pub struct Stack {
14 pub id: StackId,
16
17 pub frames: Vec<FrameId>,
19}
20
21impl Stack {
22 pub fn new(id: StackId, frames: Vec<FrameId>) -> Self {
24 Self { id, frames }
25 }
26
27 pub fn leaf(&self) -> Option<FrameId> {
29 self.frames.last().copied()
30 }
31
32 pub fn root(&self) -> Option<FrameId> {
34 self.frames.first().copied()
35 }
36
37 pub fn contains(&self, frame: FrameId) -> bool {
39 self.frames.contains(&frame)
40 }
41
42 pub fn depth(&self) -> usize {
44 self.frames.len()
45 }
46
47 pub fn is_empty(&self) -> bool {
49 self.frames.is_empty()
50 }
51}