dfdi_core/
error.rs

1use std::{
2    error::Error,
3    fmt::{Debug, Display},
4};
5
6/// Error while binding a service
7#[non_exhaustive]
8#[derive(Debug)]
9pub enum BindError {
10    /// The service has already been bound to another provider
11    ServiceBound(&'static str),
12}
13
14impl Error for BindError {}
15
16impl Display for BindError {
17    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
18        match self {
19            Self::ServiceBound(service) => {
20                write!(f, "service `{service}` is already bound to a provider")
21            }
22        }
23    }
24}
25
26/// Error while unbinding a service
27#[non_exhaustive]
28#[derive(Debug)]
29pub enum UnbindError {
30    /// The service is not bound to a provider
31    ServiceUnbound(&'static str),
32}
33
34impl Error for UnbindError {}
35
36impl Display for UnbindError {
37    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
38        match self {
39            UnbindError::ServiceUnbound(service) => {
40                write!(f, "service `{service}` is not bound to a provider")
41            }
42        }
43    }
44}