clone_stream/
error.rs

1use std::fmt;
2
3/// Errors that can occur when working with cloned streams
4
5#[derive(Debug, Clone, PartialEq, Eq)]
6pub enum CloneStreamError {
7    /// The maximum number of clones has been exceeded
8    MaxClonesExceeded {
9        max_allowed: usize,
10        current_count: usize,
11    },
12    /// Invalid clone ID provided
13    InvalidCloneId { clone_id: usize },
14    /// Clone is already active
15    CloneAlreadyActive { clone_id: usize },
16}
17
18impl fmt::Display for CloneStreamError {
19    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
20        match self {
21            Self::MaxClonesExceeded {
22                max_allowed,
23                current_count,
24            } => write!(
25                f,
26                "Maximum number of clones exceeded: {current_count} >= {max_allowed}"
27            ),
28            Self::InvalidCloneId { clone_id } => {
29                write!(f, "Invalid clone ID: {clone_id}")
30            }
31            Self::CloneAlreadyActive { clone_id } => {
32                write!(f, "Clone {clone_id} is already active")
33            }
34        }
35    }
36}
37
38impl std::error::Error for CloneStreamError {}
39
40pub type Result<T> = std::result::Result<T, CloneStreamError>;