aboutsummaryrefslogtreecommitdiff
path: root/src/errors/di_container.rs
blob: 98c2be486acd552128778e081d5a7efabda8579f (plain)
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
//! Error types for [`DIContainer`] and it's related structs.
//!
//! [`DIContainer`]: crate::di_container::DIContainer

use crate::errors::injectable::InjectableError;

/// Error type for [`DIContainer`].
///
/// [`DIContainer`]: crate::di_container::DIContainer
#[derive(thiserror::Error, Debug)]
pub enum DIContainerError
{
    /// Unable to cast a binding for a interface.
    #[error("Unable to cast binding for interface '{0}'")]
    CastFailed(&'static str),

    /// Wrong binding type.
    #[error("Wrong binding type for interface '{interface}'. Expected a {expected}. Found a {found}")]
    WrongBindingType
    {
        /// The affected bound interface.
        interface: &'static str,

        /// The expected binding type.
        expected: &'static str,

        /// The found binding type.
        found: String,
    },

    /// Failed to resolve a binding for a interface.
    #[error("Failed to resolve binding for interface '{interface}'")]
    BindingResolveFailed
    {
        /// The reason for the problem.
        #[source]
        reason: InjectableError,

        /// The affected bound interface.
        interface: &'static str,
    },

    /// No binding exists for a interface.
    #[error("No binding exists for interface '{0}'")]
    BindingNotFound(&'static str),
}

/// Error type for [`BindingBuilder`].
///
/// [`BindingBuilder`]: crate::di_container::BindingBuilder
#[derive(thiserror::Error, Debug)]
pub enum BindingBuilderError
{
    /// A binding already exists for a interface.
    #[error("Binding already exists for interface '{0}'")]
    BindingAlreadyExists(&'static str),
}

/// Error type for [`BindingScopeConfigurator`].
///
/// [`BindingBuilder`]: crate::di_container::BindingScopeConfigurator
#[derive(thiserror::Error, Debug)]
pub enum BindingScopeConfiguratorError
{
    /// Resolving a singleton failed.
    #[error("Resolving the given singleton failed")]
    SingletonResolveFailed(#[from] InjectableError),
}