1use thiserror::Error;
4
5#[derive(Debug, Error)]
7pub enum Error {
8 #[error("Buffer is full")]
10 BufferFull,
11
12 #[error("Memory allocation failed: {0}")]
14 AllocationFailed(String),
15
16 #[error("Thread safety violation: {0}")]
18 ThreadSafety(String),
19
20 #[error("Buffer corruption: {0}")]
22 Corruption(String),
23
24 #[error("Invalid configuration: {0}")]
26 Config(String),
27
28 #[error("Feature not implemented: {0}")]
30 NotImplemented(String),
31
32 #[error("QoS policy violation: {0}")]
34 QosViolation(String),
35
36 #[error("Invalid buffer capacity: {0}")]
38 InvalidCapacity(String),
39
40 #[error("Message too large for buffer: {0}")]
42 MessageTooLarge(String),
43}
44
45pub type Result<T> = std::result::Result<T, Error>;
47
48#[cfg(test)]
49mod tests {
50 use super::*;
51
52 #[test]
53 fn test_error_display() {
54 let error: Error = Error::BufferFull;
55 assert_eq!(format!("{}", error), "Buffer is full");
56
57 let error: Error = Error::AllocationFailed("out of memory".to_string());
58 assert_eq!(format!("{}", error), "Memory allocation failed: out of memory");
59 }
60}