1use std::{fmt, sync::Arc};
4
5#[derive(Debug)]
7pub struct ServiceError {
8 inner: Arc<Error>,
9}
10
11#[derive(Debug)]
13pub struct Closed {
14 _p: (),
15}
16
17pub(crate) type Error = Box<dyn std::error::Error + Send + Sync>;
19
20impl ServiceError {
23 pub(crate) fn new(inner: Error) -> ServiceError {
24 let inner = Arc::new(inner);
25 ServiceError { inner }
26 }
27
28 pub(crate) fn clone(&self) -> ServiceError {
30 ServiceError {
31 inner: self.inner.clone(),
32 }
33 }
34}
35
36impl fmt::Display for ServiceError {
37 fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
38 write!(fmt, "buffered service failed: {}", self.inner)
39 }
40}
41
42impl std::error::Error for ServiceError {
43 fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
44 Some(&**self.inner)
45 }
46}
47
48impl Closed {
51 pub(crate) fn new() -> Self {
52 Closed { _p: () }
53 }
54}
55
56impl fmt::Display for Closed {
57 fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
58 fmt.write_str("buffer's worker closed unexpectedly")
59 }
60}
61
62impl std::error::Error for Closed {}