aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorHampusM <hampus@hampusmat.com>2022-08-28 13:24:39 +0200
committerHampusM <hampus@hampusmat.com>2022-08-28 13:37:14 +0200
commitf91c4ce73786a69e4ec72f69ef4d9d5f03ac5886 (patch)
tree6ac016e731eaf7e6fabdbcf12b84852cbc5af475 /src
parentdd6ae0c8643f08114469ccff66615b45ccf5e13e (diff)
style: add rustfmt config options
Diffstat (limited to 'src')
-rw-r--r--src/di_container.rs20
-rw-r--r--src/di_container_binding_map.rs3
-rw-r--r--src/lib.rs6
-rw-r--r--src/libs/intertrait/cast/arc.rs3
-rw-r--r--src/libs/intertrait/mod.rs34
-rw-r--r--src/ptr.rs1
6 files changed, 40 insertions, 27 deletions
diff --git a/src/di_container.rs b/src/di_container.rs
index 9d54261..e42175b 100644
--- a/src/di_container.rs
+++ b/src/di_container.rs
@@ -5,7 +5,7 @@
//! use std::collections::HashMap;
//! use std::error::Error;
//!
-//! use syrette::{DIContainer, injectable};
+//! use syrette::{injectable, DIContainer};
//!
//! trait IDatabaseService
//! {
@@ -36,13 +36,15 @@
//! {
//! let mut di_container = DIContainer::new();
//!
-//! di_container.bind::<dyn IDatabaseService>().to::<DatabaseService>().map_err(|err| {
-//! err.to_string()
-//! })?;
+//! di_container
+//! .bind::<dyn IDatabaseService>()
+//! .to::<DatabaseService>()
+//! .map_err(|err| err.to_string())?;
//!
-//! let database_service = di_container.get::<dyn IDatabaseService>().map_err(|err| {
-//! err.to_string()
-//! })?.transient()?;
+//! let database_service = di_container
+//! .get::<dyn IDatabaseService>()
+//! .map_err(|err| err.to_string())?
+//! .transient()?;
//!
//! Ok(())
//! }
@@ -54,7 +56,9 @@ use std::marker::PhantomData;
use crate::castable_factory::CastableFactory;
use crate::di_container_binding_map::DIContainerBindingMap;
use crate::errors::di_container::{
- BindingBuilderError, BindingScopeConfiguratorError, BindingWhenConfiguratorError,
+ BindingBuilderError,
+ BindingScopeConfiguratorError,
+ BindingWhenConfiguratorError,
DIContainerError,
};
use crate::interfaces::injectable::Injectable;
diff --git a/src/di_container_binding_map.rs b/src/di_container_binding_map.rs
index d4b46f2..4df889d 100644
--- a/src/di_container_binding_map.rs
+++ b/src/di_container_binding_map.rs
@@ -2,7 +2,8 @@ use std::any::{type_name, TypeId};
use ahash::AHashMap;
-use crate::{errors::di_container::DIContainerError, provider::IProvider};
+use crate::errors::di_container::DIContainerError;
+use crate::provider::IProvider;
#[derive(Debug, PartialEq, Eq, Hash)]
struct DIContainerBindingKey
diff --git a/src/lib.rs b/src/lib.rs
index ae580ab..cac6ffe 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -29,7 +29,8 @@ pub mod libs;
mod di_container_binding_map;
mod provider;
-/// Shortcut for creating a DI container binding for a injectable without a declared interface.
+/// Shortcut for creating a DI container binding for a injectable without a declared
+/// interface.
///
/// This will declare a interface for the implementation.
///
@@ -63,7 +64,8 @@ macro_rules! di_container_bind {
/// ```
/// use syrette::declare_default_factory;
///
-/// trait IParser {
+/// trait IParser
+/// {
/// // Methods and etc here...
/// }
///
diff --git a/src/libs/intertrait/cast/arc.rs b/src/libs/intertrait/cast/arc.rs
index 65ae1ef..94c0482 100644
--- a/src/libs/intertrait/cast/arc.rs
+++ b/src/libs/intertrait/cast/arc.rs
@@ -23,7 +23,8 @@ pub trait CastArc
) -> Result<Arc<OtherTrait>, CastError>;
}
-/// A blanket implementation of `CastArc` for traits extending `CastFrom`, `Sync`, and `Send`.
+/// A blanket implementation of `CastArc` for traits extending `CastFrom`, `Sync`, and
+/// `Send`.
impl<CastFromSelf: ?Sized + CastFromSync> CastArc for CastFromSelf
{
fn cast<OtherTrait: ?Sized + 'static>(
diff --git a/src/libs/intertrait/mod.rs b/src/libs/intertrait/mod.rs
index a8d912b..2d62871 100644
--- a/src/libs/intertrait/mod.rs
+++ b/src/libs/intertrait/mod.rs
@@ -7,9 +7,9 @@
//! (i.e. without involving the concrete type of the backing value) is possible
//! (even no coercion from a trait object to that of its super-trait yet).
//!
-//! With this crate, any trait object with [`CastFrom`] as its super-trait can be cast directly
-//! to another trait object implemented by the underlying type if the target traits are
-//! registered beforehand with the macros provided by this crate.
+//! With this crate, any trait object with [`CastFrom`] as its super-trait can be cast
+//! directly to another trait object implemented by the underlying type if the target
+//! traits are registered beforehand with the macros provided by this crate.
//!
//!
//! Originally from Intertrait by CodeChain
@@ -64,20 +64,21 @@ fn cast_arc_panic<Trait: ?Sized + 'static>(_: Arc<dyn Any + Sync + Send>) -> Arc
}
/// A `Caster` knows how to cast a reference to or `Box` of a trait object for `Any`
-/// to a trait object of trait `Trait`. Each `Caster` instance is specific to a concrete type.
-/// That is, it knows how to cast to single specific trait implemented by single specific type.
+/// to a trait object of trait `Trait`. Each `Caster` instance is specific to a concrete
+/// type. That is, it knows how to cast to single specific trait implemented by single
+/// specific type.
///
/// An implementation of a trait for a concrete type doesn't need to manually provide
/// a `Caster`. Instead attach `#[cast_to]` to the `impl` block.
#[doc(hidden)]
pub struct Caster<Trait: ?Sized + 'static>
{
- /// Casts a `Box` holding a trait object for `Any` to another `Box` holding a trait object
- /// for trait `Trait`.
+ /// Casts a `Box` holding a trait object for `Any` to another `Box` holding a trait
+ /// object for trait `Trait`.
pub cast_box: fn(from: Box<dyn Any>) -> Box<Trait>,
- /// Casts an `Rc` holding a trait object for `Any` to another `Rc` holding a trait object
- /// for trait `Trait`.
+ /// Casts an `Rc` holding a trait object for `Any` to another `Rc` holding a trait
+ /// object for trait `Trait`.
pub cast_rc: fn(from: Rc<dyn Any>) -> Rc<Trait>,
/// Casts an `Arc` holding a trait object for `Any + Sync + Send + 'static`
@@ -114,7 +115,8 @@ impl<Trait: ?Sized + 'static> Caster<Trait>
}
}
-/// Returns a `Caster<S, Trait>` from a concrete type `S` to a trait `Trait` implemented by it.
+/// Returns a `Caster<S, Trait>` from a concrete type `S` to a trait `Trait` implemented
+/// by it.
fn caster<Trait: ?Sized + 'static>(type_id: TypeId) -> Option<&'static Caster<Trait>>
{
CASTER_MAP
@@ -122,10 +124,11 @@ fn caster<Trait: ?Sized + 'static>(type_id: TypeId) -> Option<&'static Caster<Tr
.and_then(|caster| caster.downcast_ref::<Caster<Trait>>())
}
-/// `CastFrom` must be extended by a trait that wants to allow for casting into another trait.
+/// `CastFrom` must be extended by a trait that wants to allow for casting into another
+/// trait.
///
-/// It is used for obtaining a trait object for [`Any`] from a trait object for its sub-trait,
-/// and blanket implemented for all `Sized + Any + 'static` types.
+/// It is used for obtaining a trait object for [`Any`] from a trait object for its
+/// sub-trait, and blanket implemented for all `Sized + Any + 'static` types.
///
/// # Examples
/// ```ignore
@@ -146,8 +149,9 @@ pub trait CastFrom: Any + 'static
/// and wants to allow for casting into another trait behind references and smart pointers
/// especially including `Arc`.
///
-/// It is used for obtaining a trait object for [`Any + Sync + Send + 'static`] from an object
-/// for its sub-trait, and blanket implemented for all `Sized + Sync + Send + 'static` types.
+/// It is used for obtaining a trait object for [`Any + Sync + Send + 'static`] from an
+/// object for its sub-trait, and blanket implemented for all `Sized + Sync + Send +
+/// 'static` types.
///
/// # Examples
/// ```ignore
diff --git a/src/ptr.rs b/src/ptr.rs
index 6f93fee..44fc15c 100644
--- a/src/ptr.rs
+++ b/src/ptr.rs
@@ -64,6 +64,7 @@ where
Interface: 'static + ?Sized,
{
create_as_variant_fn!(Transient);
+
create_as_variant_fn!(Singleton);
#[cfg(feature = "factory")]