ratatui_toolkit/master_layout/
pane_id.rs

1//! Pane identifier type
2
3use std::fmt;
4
5/// Unique identifier for a pane
6#[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    /// Create a new unique PaneId
13    pub fn new(_name: &str) -> Self {
14        // For now, use a simple hash of the name + counter
15        // The name parameter is for future use when we want to associate names with IDs
16        let id = NEXT_ID.fetch_add(1, std::sync::atomic::Ordering::Relaxed);
17        Self(id)
18    }
19
20    /// Get the raw ID value
21    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        // IDs should be unique even with same name
42        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}