1use core::fmt;
4use std::io;
5
6use crate::signal::Signal;
7
8#[non_exhaustive]
10#[derive(Debug)]
11pub enum Error {
12 AlreadyInstalled,
16
17 SignalRegistration {
19 signal: Signal,
21 source: io::Error,
23 },
24
25 InvalidState(&'static str),
28
29 Timeout(&'static str),
32
33 NoRuntime,
37}
38
39impl fmt::Display for Error {
40 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
41 match self {
42 Self::AlreadyInstalled => {
43 f.write_str("signal handlers already installed for this coordinator")
44 }
45 Self::SignalRegistration { signal, source } => {
46 write!(f, "failed to register handler for {signal}: {source}")
47 }
48 Self::InvalidState(s) => write!(f, "invalid coordinator state: {s}"),
49 Self::Timeout(s) => write!(f, "operation timed out: {s}"),
50 Self::NoRuntime => f.write_str(
51 "no async-runtime feature and no ctrlc-fallback feature enabled; \
52 enable `tokio`, `async-std`, or `ctrlc-fallback`",
53 ),
54 }
55 }
56}
57
58impl std::error::Error for Error {
59 fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
60 match self {
61 Self::SignalRegistration { source, .. } => Some(source),
62 _ => None,
63 }
64 }
65}
66
67pub type Result<T> = core::result::Result<T, Error>;