1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
use std::{
    error::Error,
    fmt::{Debug, Display},
};

/// Error while binding a service
#[non_exhaustive]
#[derive(Debug)]
pub enum BindError {
    /// The service has already been bound to another provider
    ServiceBound(&'static str),
}

impl Error for BindError {}

impl Display for BindError {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        match self {
            Self::ServiceBound(service) => {
                write!(f, "service `{service}` is already bound to a provider")
            }
        }
    }
}

/// Error while unbinding a service
#[non_exhaustive]
#[derive(Debug)]
pub enum UnbindError {
    /// The service is not bound to a provider
    ServiceUnbound(&'static str),
}

impl Error for UnbindError {}

impl Display for UnbindError {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        match self {
            UnbindError::ServiceUnbound(service) => {
                write!(f, "service `{service}` is not bound to a provider")
            }
        }
    }
}