aboutsummaryrefslogtreecommitdiff
path: root/src/errors/async_di_container.rs
diff options
context:
space:
mode:
authorHampusM <hampus@hampusmat.com>2022-08-29 20:52:56 +0200
committerHampusM <hampus@hampusmat.com>2022-08-29 21:01:32 +0200
commit080cc42bb1da09059dbc35049a7ded0649961e0c (patch)
tree307ee564124373616022c1ba2b4d5af80845cd92 /src/errors/async_di_container.rs
parent6e31d8f9e46fece348f329763b39b9c6f2741c07 (diff)
feat: implement async functionality
Diffstat (limited to 'src/errors/async_di_container.rs')
-rw-r--r--src/errors/async_di_container.rs79
1 files changed, 79 insertions, 0 deletions
diff --git a/src/errors/async_di_container.rs b/src/errors/async_di_container.rs
new file mode 100644
index 0000000..4f5e50a
--- /dev/null
+++ b/src/errors/async_di_container.rs
@@ -0,0 +1,79 @@
+//! Error types for [`AsyncDIContainer`] and it's related structs.
+//!
+//! ---
+//!
+//! *This module is only available if Syrette is built with the "async" feature.*
+//!
+//! [`AsyncDIContainer`]: crate::async_di_container::AsyncDIContainer
+
+use crate::errors::injectable::InjectableError;
+
+/// Error type for [`AsyncDIContainer`].
+///
+/// [`AsyncDIContainer`]: crate::async_di_container::AsyncDIContainer
+#[derive(thiserror::Error, Debug)]
+pub enum AsyncDIContainerError
+{
+ /// Unable to cast a binding for a interface.
+ #[error("Unable to cast binding for interface '{0}'")]
+ CastFailed(&'static str),
+
+ /// 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 (and optionally a name).
+ #[error(
+ "No binding exists for interface '{interface}' {}",
+ .name.map_or_else(String::new, |name| format!("with name '{}'", name))
+ )]
+ BindingNotFound
+ {
+ /// The interface that doesn't have a binding.
+ interface: &'static str,
+
+ /// The name of the binding if one exists.
+ name: Option<&'static str>,
+ },
+}
+
+/// Error type for [`AsyncBindingBuilder`].
+///
+/// [`AsyncBindingBuilder`]: crate::async_di_container::AsyncBindingBuilder
+#[derive(thiserror::Error, Debug)]
+pub enum AsyncBindingBuilderError
+{
+ /// A binding already exists for a interface.
+ #[error("Binding already exists for interface '{0}'")]
+ BindingAlreadyExists(&'static str),
+}
+
+/// Error type for [`AsyncBindingScopeConfigurator`].
+///
+/// [`AsyncBindingScopeConfigurator`]: crate::async_di_container::AsyncBindingScopeConfigurator
+#[derive(thiserror::Error, Debug)]
+pub enum AsyncBindingScopeConfiguratorError
+{
+ /// Resolving a singleton failed.
+ #[error("Resolving the given singleton failed")]
+ SingletonResolveFailed(#[from] InjectableError),
+}
+
+/// Error type for [`AsyncBindingWhenConfigurator`].
+///
+/// [`AsyncBindingWhenConfigurator`]: crate::async_di_container::AsyncBindingWhenConfigurator
+#[derive(thiserror::Error, Debug)]
+pub enum AsyncBindingWhenConfiguratorError
+{
+ /// A binding for a interface wasn't found.
+ #[error("A binding for interface '{0}' wasn't found'")]
+ BindingNotFound(&'static str),
+}