grafeo_common/memory/buffer/
region.rs1#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
8#[non_exhaustive]
9pub enum MemoryRegion {
10 GraphStorage,
12 IndexBuffers,
14 ExecutionBuffers,
16 SpillStaging,
18}
19
20impl MemoryRegion {
21 #[must_use]
23 pub const fn index(&self) -> usize {
24 match self {
25 Self::GraphStorage => 0,
26 Self::IndexBuffers => 1,
27 Self::ExecutionBuffers => 2,
28 Self::SpillStaging => 3,
29 }
30 }
31
32 #[must_use]
34 pub const fn name(&self) -> &'static str {
35 match self {
36 Self::GraphStorage => "Graph Storage",
37 Self::IndexBuffers => "Index Buffers",
38 Self::ExecutionBuffers => "Execution Buffers",
39 Self::SpillStaging => "Spill Staging",
40 }
41 }
42
43 #[must_use]
45 pub const fn all() -> [Self; 4] {
46 [
47 Self::GraphStorage,
48 Self::IndexBuffers,
49 Self::ExecutionBuffers,
50 Self::SpillStaging,
51 ]
52 }
53}
54
55impl std::fmt::Display for MemoryRegion {
56 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
57 write!(f, "{}", self.name())
58 }
59}
60
61#[cfg(test)]
62mod tests {
63 use super::*;
64
65 #[test]
66 fn test_region_indices() {
67 assert_eq!(MemoryRegion::GraphStorage.index(), 0);
68 assert_eq!(MemoryRegion::IndexBuffers.index(), 1);
69 assert_eq!(MemoryRegion::ExecutionBuffers.index(), 2);
70 assert_eq!(MemoryRegion::SpillStaging.index(), 3);
71 }
72
73 #[test]
74 fn test_region_names() {
75 assert_eq!(MemoryRegion::GraphStorage.name(), "Graph Storage");
76 assert_eq!(MemoryRegion::ExecutionBuffers.name(), "Execution Buffers");
77 }
78
79 #[test]
80 fn test_region_all() {
81 let all = MemoryRegion::all();
82 assert_eq!(all.len(), 4);
83 }
84}