aboutsummaryrefslogtreecommitdiff
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
parentdd6ae0c8643f08114469ccff66615b45ccf5e13e (diff)
style: add rustfmt config options
-rw-r--r--macros/src/injectable_impl.rs3
-rw-r--r--macros/src/lib.rs33
-rw-r--r--macros/src/libs/intertrait_macros/gen_caster.rs7
-rw-r--r--rustfmt.toml7
-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
10 files changed, 66 insertions, 51 deletions
diff --git a/macros/src/injectable_impl.rs b/macros/src/injectable_impl.rs
index 6edcab3..990b148 100644
--- a/macros/src/injectable_impl.rs
+++ b/macros/src/injectable_impl.rs
@@ -2,8 +2,7 @@ use std::error::Error;
use quote::{format_ident, quote, ToTokens};
use syn::parse::{Parse, ParseStream};
-use syn::Generics;
-use syn::{parse_str, ExprMethodCall, FnArg, ItemImpl, Type};
+use syn::{parse_str, ExprMethodCall, FnArg, Generics, ItemImpl, Type};
use crate::dependency::Dependency;
use crate::util::item_impl::find_impl_method_by_name_mut;
diff --git a/macros/src/lib.rs b/macros/src/lib.rs
index c7157c8..6e3fc0a 100644
--- a/macros/src/lib.rs
+++ b/macros/src/lib.rs
@@ -29,7 +29,8 @@ use libs::intertrait_macros::gen_caster::generate_caster;
/// * (Zero or more) Flags wrapped in curly braces. Like `{ a = true, b = false }`
///
/// # Flags
-/// - `no_doc_hidden` - Don't hide the impl of the [`Injectable`] trait from documentation.
+/// - `no_doc_hidden` - Don't hide the impl of the [`Injectable`] trait from
+/// documentation.
///
/// # Panics
/// If the attributed item is not a impl.
@@ -68,14 +69,15 @@ use libs::intertrait_macros::gen_caster::generate_caster;
/// impl Knight
/// {
/// pub fn new(
-/// #[named("tough")]
-/// tough_armor: TransientPtr<dyn IArmor>,
+/// #[named("tough")] tough_armor: TransientPtr<dyn IArmor>,
///
-/// #[named("light")]
-/// light_armor: TransientPtr<dyn IArmor>
+/// #[named("light")] light_armor: TransientPtr<dyn IArmor>,
/// ) -> Self
/// {
-/// Self { tough_armor, light_armor }
+/// Self {
+/// tough_armor,
+/// light_armor,
+/// }
/// }
/// }
/// #
@@ -145,8 +147,8 @@ pub fn injectable(args_stream: TokenStream, impl_stream: TokenStream) -> TokenSt
/// ```
/// use std::collections::HashMap;
///
-/// use syrette::interfaces::factory::IFactory;
/// use syrette::factory;
+/// use syrette::interfaces::factory::IFactory;
///
/// enum ConfigValue
/// {
@@ -161,7 +163,8 @@ pub fn injectable(args_stream: TokenStream, impl_stream: TokenStream) -> TokenSt
/// fn configure(&self, key: String, value: ConfigValue);
/// }
///
-/// struct Configurator {
+/// struct Configurator
+/// {
/// config: HashMap<String, ConfigValue>,
/// }
///
@@ -171,11 +174,10 @@ pub fn injectable(args_stream: TokenStream, impl_stream: TokenStream) -> TokenSt
/// {
/// Self {
/// config: HashMap::from(
-/// keys
-/// .iter()
+/// keys.iter()
/// .map(|key| (key.clone(), ConfigValue::None))
-/// .collect::<HashMap<_, _>>()
-/// )
+/// .collect::<HashMap<_, _>>(),
+/// ),
/// }
/// }
/// }
@@ -226,7 +228,6 @@ pub fn factory(_: TokenStream, type_alias_stream: TokenStream) -> TokenStream
///
/// # Arguments
/// {Implementation} -> {Interface}
-///
#[proc_macro]
pub fn declare_interface(input: TokenStream) -> TokenStream
{
@@ -265,11 +266,9 @@ pub fn declare_interface(input: TokenStream) -> TokenStream
/// impl Ninja
/// {
/// pub fn new(
-/// #[syrette::named("strong")]
-/// strong_weapon: TransientPtr<dyn IWeapon>,
+/// #[syrette::named("strong")] strong_weapon: TransientPtr<dyn IWeapon>,
///
-/// #[syrette::named("weak")]
-/// weak_weapon: TransientPtr<dyn IWeapon>,
+/// #[syrette::named("weak")] weak_weapon: TransientPtr<dyn IWeapon>,
/// ) -> Self
/// {
/// Self {
diff --git a/macros/src/libs/intertrait_macros/gen_caster.rs b/macros/src/libs/intertrait_macros/gen_caster.rs
index d77262a..9bac09e 100644
--- a/macros/src/libs/intertrait_macros/gen_caster.rs
+++ b/macros/src/libs/intertrait_macros/gen_caster.rs
@@ -13,11 +13,8 @@
*/
use std::str::from_utf8;
-use proc_macro2::Ident;
-use proc_macro2::TokenStream;
-use quote::format_ident;
-use quote::quote;
-use quote::ToTokens;
+use proc_macro2::{Ident, TokenStream};
+use quote::{format_ident, quote, ToTokens};
use uuid::adapter::Simple;
use uuid::Uuid;
diff --git a/rustfmt.toml b/rustfmt.toml
index b689c7b..4d1e29f 100644
--- a/rustfmt.toml
+++ b/rustfmt.toml
@@ -1,4 +1,11 @@
max_width = 90
brace_style = "AlwaysNextLine"
group_imports = "StdExternalCrate"
+wrap_comments = true
+comment_width = 90
+format_code_in_doc_comments = true
+imports_layout = "HorizontalVertical"
+imports_granularity = "Module"
+newline_style = "Unix"
+reorder_impl_items = true
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")]