ratatui_toolkit/master_layout/
pane_id.rs1use std::fmt;
4
5#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
7pub struct PaneId(u64);
8
9static NEXT_ID: std::sync::atomic::AtomicU64 = std::sync::atomic::AtomicU64::new(0);
10
11impl PaneId {
12 pub fn new(_name: &str) -> Self {
14 let id = NEXT_ID.fetch_add(1, std::sync::atomic::Ordering::Relaxed);
17 Self(id)
18 }
19
20 pub fn raw(&self) -> u64 {
22 self.0
23 }
24}
25
26impl fmt::Display for PaneId {
27 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
28 write!(f, "PaneId({})", self.0)
29 }
30}
31
32#[cfg(test)]
33mod tests {
34 use super::*;
35
36 #[test]
37 fn test_pane_id_creation() {
38 let id1 = PaneId::new("test");
39 let id2 = PaneId::new("test");
40
41 assert_ne!(id1, id2);
43 }
44
45 #[test]
46 fn test_pane_id_equality() {
47 let id = PaneId::new("test");
48 assert_eq!(id, id);
49 }
50
51 #[test]
52 fn test_pane_id_display() {
53 let id = PaneId::new("test");
54 let display = format!("{}", id);
55 assert!(display.starts_with("PaneId("));
56 }
57}