Skip to main content

leyline/core/error/
marker.rs

1use std::fmt;
2
3use super::{Error, Kind};
4
5#[derive(Debug)]
6pub(crate) struct ShutDown;
7
8impl fmt::Display for ShutDown {
9    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
10        f.write_str(SHUT_DOWN_MESSAGE)
11    }
12}
13
14impl std::error::Error for ShutDown {}
15
16#[derive(Debug)]
17#[cfg_attr(not(feature = "http3"), expect(dead_code))]
18pub(crate) struct NotProcessed;
19
20impl fmt::Display for NotProcessed {
21    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
22        f.write_str("the server did not process the request")
23    }
24}
25
26impl std::error::Error for NotProcessed {}
27
28const SHUT_DOWN_MESSAGE: &str = "session shut down";
29
30impl Error {
31    pub(crate) fn shut_down() -> Error {
32        Error::new(Kind::Request)
33            .with_message(SHUT_DOWN_MESSAGE)
34            .with_source(ShutDown)
35    }
36
37    pub fn is_shut_down(&self) -> bool {
38        self.source_as::<ShutDown>().is_some()
39    }
40
41    pub(crate) fn not_processed(&self) -> bool {
42        self.source_as::<NotProcessed>().is_some()
43    }
44}