Skip to main content

ruccl/in_process/
error.rs

1use std::error::Error;
2use std::fmt::{Display, Formatter};
3
4#[derive(Debug)]
5pub enum InProcessError {
6    EmptyWorld,
7    RankOutOfRange { rank: usize, world_size: usize },
8    WrongCommunicator,
9    InvalidLength(&'static str),
10    Overflow(&'static str),
11}
12
13impl Display for InProcessError {
14    fn fmt(&self, formatter: &mut Formatter<'_>) -> std::fmt::Result {
15        match self {
16            Self::EmptyWorld => {
17                write!(formatter, "collective world must contain at least one rank")
18            }
19            Self::RankOutOfRange { rank, world_size } => write!(
20                formatter,
21                "rank {rank} is outside collective world size {world_size}"
22            ),
23            Self::WrongCommunicator => write!(
24                formatter,
25                "distributed buffer belongs to another communicator"
26            ),
27            Self::InvalidLength(message) => {
28                write!(formatter, "invalid collective length: {message}")
29            }
30            Self::Overflow(what) => {
31                write!(formatter, "collective size overflow while computing {what}")
32            }
33        }
34    }
35}
36
37impl Error for InProcessError {}