tower_memlim/
error.rs

1//! Error types
2
3use std::fmt;
4
5pub type BoxError = Box<dyn std::error::Error + Send + Sync>;
6
7/// An error returned by [`MemoryLimit`] when the service's
8/// memory checker was unable to determine the available amount of memory.
9///
10/// [`MemoryLimit`]: crate::service::MemoryLimit
11#[derive(Default)]
12pub struct MemCheckFailure {
13    inner: Option<BoxError>,
14}
15
16impl MemCheckFailure {
17    /// Construct a new overloaded error
18    pub const fn new(inner: BoxError) -> Self {
19        MemCheckFailure { inner: Some(inner)  }
20    }
21}
22
23impl fmt::Debug for MemCheckFailure {
24    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
25        f.write_str(format!("Failed to determine available memory: {:?}", self.inner).as_str())
26    }
27}
28
29impl fmt::Display for MemCheckFailure {
30    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
31        f.write_str(format!("Failed to determine available memory: {:?}", self.inner).as_str())
32    }
33}
34
35impl std::error::Error for MemCheckFailure {}