clone_stream/
error.rs

1use std::fmt;
2
3/// Errors that can occur when working with cloned streams
4#[derive(Debug, Clone, PartialEq)]
5pub enum CloneStreamError {
6    /// The maximum number of clones has been exceeded
7    MaxClonesExceeded {
8        max_allowed: usize,
9        current_count: usize,
10    },
11    /// The maximum queue size has been exceeded
12    MaxQueueSizeExceeded {
13        max_allowed: usize,
14        current_size: usize,
15    },
16    /// Attempted to access a clone that doesn't exist
17    CloneNotFound { clone_id: usize },
18    /// The fork is in an invalid state
19    InvalidForkState { message: String },
20}
21
22impl fmt::Display for CloneStreamError {
23    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
24        match self {
25            CloneStreamError::MaxClonesExceeded {
26                max_allowed,
27                current_count,
28            } => write!(
29                f,
30                "Maximum number of clones exceeded: {current_count} >= {max_allowed}"
31            ),
32            CloneStreamError::MaxQueueSizeExceeded {
33                max_allowed,
34                current_size,
35            } => write!(
36                f,
37                "Maximum queue size exceeded: {current_size} >= {max_allowed}"
38            ),
39            CloneStreamError::CloneNotFound { clone_id } => {
40                write!(f, "Clone with ID {clone_id} not found")
41            }
42            CloneStreamError::InvalidForkState { message } => {
43                write!(f, "Invalid fork state: {message}")
44            }
45        }
46    }
47}
48
49impl std::error::Error for CloneStreamError {}
50
51/// Result type for clone stream operations
52pub type Result<T> = std::result::Result<T, CloneStreamError>;