Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Release 3.1 #20

Merged
merged 7 commits into from
Dec 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
166 changes: 83 additions & 83 deletions guide/src/guide/links.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,92 +8,92 @@ REF: https://github.com/rust-lang/cargo/issues/739
REF: https://github.com/tag1consulting/goose/issues/320
-->

[`Ref`]: https://docs.rs/more-di/3.0.0/di/type.Ref.html
[`Type`]: https://docs.rs/more-di/3.0.0/di/struct.Type.html
[`ServiceCardinality`]: https://docs.rs/more-di/3.0.0/di/enum.ServiceCardinality.html
[`ServiceLifetime`]: https://docs.rs/more-di/3.0.0/di/enum.ServiceLifetime.html
[`ServiceDependency`]: https://docs.rs/more-di/3.0.0/di/struct.ServiceDependency.html
[`ServiceDescriptor`]: https://docs.rs/more-di/3.0.0/di/struct.ServiceDescriptor.html
[`Ref`]: https://docs.rs/more-di/3.1.0/di/type.Ref.html
[`Type`]: https://docs.rs/more-di/3.1.0/di/struct.Type.html
[`ServiceCardinality`]: https://docs.rs/more-di/3.1.0/di/enum.ServiceCardinality.html
[`ServiceLifetime`]: https://docs.rs/more-di/3.1.0/di/enum.ServiceLifetime.html
[`ServiceDependency`]: https://docs.rs/more-di/3.1.0/di/struct.ServiceDependency.html
[`ServiceDescriptor`]: https://docs.rs/more-di/3.1.0/di/struct.ServiceDescriptor.html

[`ServiceCollection`]: https://docs.rs/more-di/3.0.0/di/struct.ServiceCollection.html
[`ServiceCollection::build_provider()`]: https://docs.rs/more-di/3.0.0/di/struct.ServiceCollection.html#method.build_provider
[`add`]: https://docs.rs/more-di/3.0.0/di/struct.ServiceCollection.html#method.add
[`try_add`]: https://docs.rs/more-di/3.0.0/di/struct.ServiceCollection.html#method.try_add
[`try_add_to_all`]: https://docs.rs/more-di/3.0.0/di/struct.ServiceCollection.html#method.try_add_to_all
[`try_add_all`]: https://docs.rs/more-di/3.0.0/di/struct.ServiceCollection.html#method.try_add_all
[`replace`]: https://docs.rs/more-di/3.0.0/di/struct.ServiceCollection.html#method.replace
[`try_replace`]: https://docs.rs/more-di/3.0.0/di/struct.ServiceCollection.html#method.try_replace
[`ServiceCollection`]: https://docs.rs/more-di/3.1.0/di/struct.ServiceCollection.html
[`ServiceCollection::build_provider()`]: https://docs.rs/more-di/3.1.0/di/struct.ServiceCollection.html#method.build_provider
[`add`]: https://docs.rs/more-di/3.1.0/di/struct.ServiceCollection.html#method.add
[`try_add`]: https://docs.rs/more-di/3.1.0/di/struct.ServiceCollection.html#method.try_add
[`try_add_to_all`]: https://docs.rs/more-di/3.1.0/di/struct.ServiceCollection.html#method.try_add_to_all
[`try_add_all`]: https://docs.rs/more-di/3.1.0/di/struct.ServiceCollection.html#method.try_add_all
[`replace`]: https://docs.rs/more-di/3.1.0/di/struct.ServiceCollection.html#method.replace
[`try_replace`]: https://docs.rs/more-di/3.1.0/di/struct.ServiceCollection.html#method.try_replace

[`ValidationError`]: https://docs.rs/more-di/3.0.0/di/struct.ValidationError.html
[`validate`]: https://docs.rs/more-di/3.0.0/di/fn.validate.html
[`ValidationError`]: https://docs.rs/more-di/3.1.0/di/struct.ValidationError.html
[`validate`]: https://docs.rs/more-di/3.1.0/di/fn.validate.html

[`ServiceProvider`]: https://docs.rs/more-di/3.0.0/di/struct.ServiceProvider.html
[`ScopedServiceProvider`]: https://docs.rs/more-di/3.0.0/di/struct.ScopedServiceProvider.html
[`create_scope`]: https://docs.rs/more-di/3.0.0/di/struct.ServiceProvider.html#method.create_scope
[`get`]: https://docs.rs/more-di/3.0.0/di/struct.ServiceProvider.html#method.get
[`get_mut`]: https://docs.rs/more-di/3.0.0/di/struct.ServiceProvider.html#method.get_mut
[`get_by_key`]: https://docs.rs/more-di/3.0.0/di/struct.ServiceProvider.html#method.get_by_key
[`get_by_key_mut`]: https://docs.rs/more-di/3.0.0/di/struct.ServiceProvider.html#method.get_by_key_mut
[`get_all`]: https://docs.rs/more-di/3.0.0/di/struct.ServiceProvider.html#method.get_all
[`get_all_mut`]: https://docs.rs/more-di/3.0.0/di/struct.ServiceProvider.html#method.get_all_mut
[`get_all_by_key`]: https://docs.rs/more-di/3.0.0/di/struct.ServiceProvider.html#method.get_all_by_key
[`get_all_by_key_mut`]: https://docs.rs/more-di/3.0.0/di/struct.ServiceProvider.html#method.get_all_by_key_mut
[`get_required`]: https://docs.rs/more-di/3.0.0/di/struct.ServiceProvider.html#method.get_required
[`get_required_mut`]: https://docs.rs/more-di/3.0.0/di/struct.ServiceProvider.html#method.get_required_mut
[`get_required_by_key`]: https://docs.rs/more-di/3.0.0/di/struct.ServiceProvider.html#method.get_required_by_key
[`get_required_by_key_mut`]: https://docs.rs/more-di/3.0.0/di/struct.ServiceProvider.html#method.get_required_by_key_mut
[`ServiceProvider`]: https://docs.rs/more-di/3.1.0/di/struct.ServiceProvider.html
[`ScopedServiceProvider`]: https://docs.rs/more-di/3.1.0/di/struct.ScopedServiceProvider.html
[`create_scope`]: https://docs.rs/more-di/3.1.0/di/struct.ServiceProvider.html#method.create_scope
[`get`]: https://docs.rs/more-di/3.1.0/di/struct.ServiceProvider.html#method.get
[`get_mut`]: https://docs.rs/more-di/3.1.0/di/struct.ServiceProvider.html#method.get_mut
[`get_by_key`]: https://docs.rs/more-di/3.1.0/di/struct.ServiceProvider.html#method.get_by_key
[`get_by_key_mut`]: https://docs.rs/more-di/3.1.0/di/struct.ServiceProvider.html#method.get_by_key_mut
[`get_all`]: https://docs.rs/more-di/3.1.0/di/struct.ServiceProvider.html#method.get_all
[`get_all_mut`]: https://docs.rs/more-di/3.1.0/di/struct.ServiceProvider.html#method.get_all_mut
[`get_all_by_key`]: https://docs.rs/more-di/3.1.0/di/struct.ServiceProvider.html#method.get_all_by_key
[`get_all_by_key_mut`]: https://docs.rs/more-di/3.1.0/di/struct.ServiceProvider.html#method.get_all_by_key_mut
[`get_required`]: https://docs.rs/more-di/3.1.0/di/struct.ServiceProvider.html#method.get_required
[`get_required_mut`]: https://docs.rs/more-di/3.1.0/di/struct.ServiceProvider.html#method.get_required_mut
[`get_required_by_key`]: https://docs.rs/more-di/3.1.0/di/struct.ServiceProvider.html#method.get_required_by_key
[`get_required_by_key_mut`]: https://docs.rs/more-di/3.1.0/di/struct.ServiceProvider.html#method.get_required_by_key_mut

[`Injectable`]: https://docs.rs/more-di/3.0.0/di/trait.Injectable.html
[`InjectBuilder`]: https://docs.rs/more-di/3.0.0/di/struct.InjectBuilder.html
[`as_mut`]: https://docs.rs/more-di/3.0.0/di/struct.InjectBuilder.html#method.as_mut
[`with_key<TKey>`]: https://docs.rs/more-di/3.0.0/di/struct.InjectBuilder.html#method.with_key
[`Injectable`]: https://docs.rs/more-di/3.1.0/di/trait.Injectable.html
[`InjectBuilder`]: https://docs.rs/more-di/3.1.0/di/struct.InjectBuilder.html
[`as_mut`]: https://docs.rs/more-di/3.1.0/di/struct.InjectBuilder.html#method.as_mut
[`with_key<TKey>`]: https://docs.rs/more-di/3.1.0/di/struct.InjectBuilder.html#method.with_key

[`ServiceDescriptorBuilder`]: https://docs.rs/more-di/3.0.0/di/struct.ServiceDescriptorBuilder.html
[`singleton`]: https://docs.rs/more-di/3.0.0/di/fn.singleton.html
[`singleton_as_self`]: https://docs.rs/more-di/3.0.0/di/fn.singleton_as_self.html
[`singleton_factory`]: https://docs.rs/more-di/3.0.0/di/fn.singleton_factory.html
[`singleton_with_key`]: https://docs.rs/more-di/3.0.0/di/fn.singleton_with_key.html
[`singleton_with_key_factory`]: https://docs.rs/more-di/3.0.0/di/fn.singleton_with_key_factory.html
[`scoped`]: https://docs.rs/more-di/3.0.0/di/fn.scoped.html
[`scoped_factory`]: https://docs.rs/more-di/3.0.0/di/fn.scoped_factory.html
[`scoped_with_key`]: https://docs.rs/more-di/3.0.0/di/fn.scoped_with_key.html
[`scoped_with_key_factory`]: https://docs.rs/more-di/3.0.0/di/fn.scoped_with_key_factory.html
[`transient`]: https://docs.rs/more-di/3.0.0/di/fn.transient.html
[`transient_factory`]: https://docs.rs/more-di/3.0.0/di/fn.transient_factory.html
[`transient_as_self`]: https://docs.rs/more-di/3.0.0/di/fn.transient_as_self.html
[`transient_with_key`]: https://docs.rs/more-di/3.0.0/di/fn.transient_with_key.html
[`transient_with_key_factory`]: https://docs.rs/more-di/3.0.0/di/fn.transient_with_key_factory.html
[`transient_with_key_as_self`]: https://docs.rs/more-di/3.0.0/di/fn.transient_with_key_as_self.html
[`existing`]: https://docs.rs/more-di/3.0.0/di/fn.existing.html
[`existing_as_self`]: https://docs.rs/more-di/3.0.0/di/fn.existing_as_self.html
[`existing_with_key`]: https://docs.rs/more-di/3.0.0/di/fn.existing_with_key.html
[`existing_with_key_as_self`]: https://docs.rs/more-di/3.0.0/di/fn.existing_with_key_as_self.html
[`exactly_one`]: https://docs.rs/more-di/3.0.0/di/fn.exactly_one.html
[`exactly_one_with_key`]: https://docs.rs/more-di/3.0.0/di/fn.exactly_one_with_key.html
[`zero_or_one`]: https://docs.rs/more-di/3.0.0/di/fn.zero_or_one.html
[`zero_or_one_with_key`]: https://docs.rs/more-di/3.0.0/di/fn.zero_or_one_with_key.html
[`zero_or_more`]: https://docs.rs/more-di/3.0.0/di/fn.zero_or_more.html
[`zero_or_more_with_key`]: https://docs.rs/more-di/3.0.0/di/fn.zero_or_more_with_key.html
[`ServiceDescriptorBuilder`]: https://docs.rs/more-di/3.1.0/di/struct.ServiceDescriptorBuilder.html
[`singleton`]: https://docs.rs/more-di/3.1.0/di/fn.singleton.html
[`singleton_as_self`]: https://docs.rs/more-di/3.1.0/di/fn.singleton_as_self.html
[`singleton_factory`]: https://docs.rs/more-di/3.1.0/di/fn.singleton_factory.html
[`singleton_with_key`]: https://docs.rs/more-di/3.1.0/di/fn.singleton_with_key.html
[`singleton_with_key_factory`]: https://docs.rs/more-di/3.1.0/di/fn.singleton_with_key_factory.html
[`scoped`]: https://docs.rs/more-di/3.1.0/di/fn.scoped.html
[`scoped_factory`]: https://docs.rs/more-di/3.1.0/di/fn.scoped_factory.html
[`scoped_with_key`]: https://docs.rs/more-di/3.1.0/di/fn.scoped_with_key.html
[`scoped_with_key_factory`]: https://docs.rs/more-di/3.1.0/di/fn.scoped_with_key_factory.html
[`transient`]: https://docs.rs/more-di/3.1.0/di/fn.transient.html
[`transient_factory`]: https://docs.rs/more-di/3.1.0/di/fn.transient_factory.html
[`transient_as_self`]: https://docs.rs/more-di/3.1.0/di/fn.transient_as_self.html
[`transient_with_key`]: https://docs.rs/more-di/3.1.0/di/fn.transient_with_key.html
[`transient_with_key_factory`]: https://docs.rs/more-di/3.1.0/di/fn.transient_with_key_factory.html
[`transient_with_key_as_self`]: https://docs.rs/more-di/3.1.0/di/fn.transient_with_key_as_self.html
[`existing`]: https://docs.rs/more-di/3.1.0/di/fn.existing.html
[`existing_as_self`]: https://docs.rs/more-di/3.1.0/di/fn.existing_as_self.html
[`existing_with_key`]: https://docs.rs/more-di/3.1.0/di/fn.existing_with_key.html
[`existing_with_key_as_self`]: https://docs.rs/more-di/3.1.0/di/fn.existing_with_key_as_self.html
[`exactly_one`]: https://docs.rs/more-di/3.1.0/di/fn.exactly_one.html
[`exactly_one_with_key`]: https://docs.rs/more-di/3.1.0/di/fn.exactly_one_with_key.html
[`zero_or_one`]: https://docs.rs/more-di/3.1.0/di/fn.zero_or_one.html
[`zero_or_one_with_key`]: https://docs.rs/more-di/3.1.0/di/fn.zero_or_one_with_key.html
[`zero_or_more`]: https://docs.rs/more-di/3.1.0/di/fn.zero_or_more.html
[`zero_or_more_with_key`]: https://docs.rs/more-di/3.1.0/di/fn.zero_or_more_with_key.html

[`lazy`]: https://docs.rs/more-di/3.0.0/di/lazy/index.html
[`Lazy`]: https://docs.rs/more-di/3.0.0/di/lazy/struct.Lazy.html
[`lazy::exactly_one`]: https://docs.rs/more-di/3.0.0/di/lazy/fn.exactly_one.html
[`lazy::exactly_one_mut`]: https://docs.rs/more-di/3.0.0/di/lazy/fn.exactly_one_mut.html
[`lazy::exactly_one_with_key`]: https://docs.rs/more-di/3.0.0/di/lazy/fn.exactly_one_with_key.html
[`lazy::exactly_one_with_key_mut`]: https://docs.rs/more-di/3.0.0/di/lazy/fn.exactly_one_with_key_mut.html
[`lazy::zero_or_one`]: https://docs.rs/more-di/3.0.0/di/lazy/fn.zero_or_one.html
[`lazy::zero_or_one_mut`]: https://docs.rs/more-di/3.0.0/di/lazy/fn.zero_or_one_mut.html
[`lazy::zero_or_one_by_key`]: https://docs.rs/more-di/3.0.0/di/lazy/fn.zero_or_one_by_key.html
[`lazy::zero_or_one_by_key_mut`]: https://docs.rs/more-di/3.0.0/di/lazy/fn.zero_or_one_by_key_mut.html
[`lazy::zero_or_more`]: https://docs.rs/more-di/3.0.0/di/lazy/fn.zero_or_more.html
[`lazy::zero_or_more_mut`]: https://docs.rs/more-di/3.0.0/di/lazy/fn.zero_or_more_mut.html
[`lazy::zero_or_more_by_key`]: https://docs.rs/more-di/3.0.0/di/lazy/fn.zero_or_more_by_key.html
[`lazy::zero_or_more_by_key_mut`]: https://docs.rs/more-di/3.0.0/di/lazy/fn.zero_or_more_by_key_mut.html
[`lazy::missing`]: https://docs.rs/more-di/3.0.0/di/lazy/fn.missing.html
[`lazy::missing_with_key`]: https://docs.rs/more-di/3.0.0/di/lazy/fn.missing_with_key.html
[`lazy::empty`]: https://docs.rs/more-di/3.0.0/di/lazy/fn.empty.html
[`lazy::empty_with_key`]: https://docs.rs/more-di/3.0.0/di/lazy/fn.empty_with_key.html
[`lazy::init`]: https://docs.rs/more-di/3.0.0/di/lazy/fn.init.html
[`lazy::init_mut`]: https://docs.rs/more-di/3.0.0/di/lazy/fn.init_mut.html
[`lazy::init_by_key`]: https://docs.rs/more-di/3.0.0/di/lazy/fn.init_by_key.html
[`lazy::init_by_key_mut`]: https://docs.rs/more-di/3.0.0/di/lazy/fn.init_by_key_mut.html
[`lazy`]: https://docs.rs/more-di/3.1.0/di/lazy/index.html
[`Lazy`]: https://docs.rs/more-di/3.1.0/di/lazy/struct.Lazy.html
[`lazy::exactly_one`]: https://docs.rs/more-di/3.1.0/di/lazy/fn.exactly_one.html
[`lazy::exactly_one_mut`]: https://docs.rs/more-di/3.1.0/di/lazy/fn.exactly_one_mut.html
[`lazy::exactly_one_with_key`]: https://docs.rs/more-di/3.1.0/di/lazy/fn.exactly_one_with_key.html
[`lazy::exactly_one_with_key_mut`]: https://docs.rs/more-di/3.1.0/di/lazy/fn.exactly_one_with_key_mut.html
[`lazy::zero_or_one`]: https://docs.rs/more-di/3.1.0/di/lazy/fn.zero_or_one.html
[`lazy::zero_or_one_mut`]: https://docs.rs/more-di/3.1.0/di/lazy/fn.zero_or_one_mut.html
[`lazy::zero_or_one_by_key`]: https://docs.rs/more-di/3.1.0/di/lazy/fn.zero_or_one_by_key.html
[`lazy::zero_or_one_by_key_mut`]: https://docs.rs/more-di/3.1.0/di/lazy/fn.zero_or_one_by_key_mut.html
[`lazy::zero_or_more`]: https://docs.rs/more-di/3.1.0/di/lazy/fn.zero_or_more.html
[`lazy::zero_or_more_mut`]: https://docs.rs/more-di/3.1.0/di/lazy/fn.zero_or_more_mut.html
[`lazy::zero_or_more_by_key`]: https://docs.rs/more-di/3.1.0/di/lazy/fn.zero_or_more_by_key.html
[`lazy::zero_or_more_by_key_mut`]: https://docs.rs/more-di/3.1.0/di/lazy/fn.zero_or_more_by_key_mut.html
[`lazy::missing`]: https://docs.rs/more-di/3.1.0/di/lazy/fn.missing.html
[`lazy::missing_with_key`]: https://docs.rs/more-di/3.1.0/di/lazy/fn.missing_with_key.html
[`lazy::empty`]: https://docs.rs/more-di/3.1.0/di/lazy/fn.empty.html
[`lazy::empty_with_key`]: https://docs.rs/more-di/3.1.0/di/lazy/fn.empty_with_key.html
[`lazy::init`]: https://docs.rs/more-di/3.1.0/di/lazy/fn.init.html
[`lazy::init_mut`]: https://docs.rs/more-di/3.1.0/di/lazy/fn.init_mut.html
[`lazy::init_by_key`]: https://docs.rs/more-di/3.1.0/di/lazy/fn.init_by_key.html
[`lazy::init_by_key_mut`]: https://docs.rs/more-di/3.1.0/di/lazy/fn.init_by_key_mut.html
24 changes: 24 additions & 0 deletions guide/src/guide/macros.md
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,30 @@ pub trait Foo;
pub struct FooImpl;
```

### Multiple Traits

In most scenarios where you want to inject a trait, you will specify a single trait. There are a limited number of edge cases where you might need to specify multiple traits. The most common use case will be implementing a trait for a struct that is thread-safe, but the trait definition does not declare that itself.

```rust
use di::*;

pub trait Foo;

#[injectable(Foo + Send + Sync)] // dyn Foo + Send + Sync → FooImpl
pub struct FooImpl;
```

Note that the combination of all traits now defines the service. The complete set of traits must be specified in order to resolve the service.

```rust
let provider = ServiceCollection::new()
.add(FooImpl::transient())
.build_provider()
.unwrap();

let foo = provider.get_required::<dyn Foo + Send + Sync>();
```

### Injection Rules

The most basic form of injection allows `#[injectable]` to be applied to any struct or tuple struct, including generics.
Expand Down
4 changes: 2 additions & 2 deletions src/di/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "more-di"
version = "3.0.0"
version = "3.1.0"
edition = "2018"
authors = ["Chris Martinez <[email protected]>"]
description = "Provides support for dependency injection (DI)"
Expand Down Expand Up @@ -32,7 +32,7 @@ alias = ["more-di-macros/alias"]

[dependencies.more-di-macros]
path = "../di_macros"
version = "3.0"
version = "3.1"
optional = true

[dependencies.spin]
Expand Down
11 changes: 10 additions & 1 deletion src/di/keyed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use crate::{Mut, Ref};
use std::{any::Any, borrow::Borrow, marker::PhantomData, ops::Deref};

/// Represents a holder for a keyed service.
#[derive(Clone)]
#[derive(Debug)]
pub struct KeyedRef<TKey, TSvc: Any + ?Sized> {
service: Ref<TSvc>,
_key: PhantomData<TKey>,
Expand All @@ -23,6 +23,15 @@ impl<TKey, TSvc: Any + ?Sized> KeyedRef<TKey, TSvc> {
}
}

impl<TKey, TSvc: Any + ?Sized> Clone for KeyedRef<TKey, TSvc> {
fn clone(&self) -> Self {
Self {
service: self.service.clone(),
_key: PhantomData,
}
}
}

impl<TKey, TSvc: Any + ?Sized> From<KeyedRef<TKey, TSvc>> for Ref<TSvc> {
fn from(value: KeyedRef<TKey, TSvc>) -> Self {
value.service
Expand Down
12 changes: 10 additions & 2 deletions src/di/lib.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,19 @@
#![doc = include_str!("README.md")]
#![cfg_attr(docsrs, feature(doc_cfg))]

// Mut<T> is public primarily for code generation in the proc macro. it is
// generally uninteresting, but is required because, while we can detect a
// mutable service, we don't know which alias is behind the 'async' feature.
// the documentation will remain hidden to avoid confusion unless you really,
// really know and need to use it.

#[doc(hidden)]
#[cfg(not(feature = "async"))]
pub(crate) type Mut<T> = std::cell::RefCell<T>;
pub type Mut<T> = std::cell::RefCell<T>;

#[doc(hidden)]
#[cfg(feature = "async")]
pub(crate) type Mut<T> = std::sync::RwLock<T>;
pub type Mut<T> = std::sync::RwLock<T>;

mod collection;
mod dependency;
Expand Down
2 changes: 1 addition & 1 deletion src/di_macros/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "more-di-macros"
version = "3.0.0"
version = "3.1.0"
edition = "2018"
authors = ["Chris Martinez <[email protected]>"]
description = "Macro implementation of #[injectable(Trait)]"
Expand Down
6 changes: 3 additions & 3 deletions src/di_macros/internal/attribute.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
use syn::{
parse::{Parse, ParseStream},
Path, Result,
Path, Result, punctuated::Punctuated, token::Plus,
};

pub struct InjectableAttribute {
pub trait_: Option<Path>,
pub trait_: Option<Punctuated<Path, Plus>>,
}

impl Parse for InjectableAttribute {
fn parse(input: ParseStream) -> Result<Self> {
Ok(Self {
trait_: input.parse().ok(),
trait_: input.parse_terminated(Path::parse, Plus).ok(),
})
}
}
14 changes: 9 additions & 5 deletions src/di_macros/internal/derive.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use syn::{Generics, ItemStruct, Path, Signature};
use syn::{punctuated::Punctuated, token::Plus, Generics, ItemStruct, Path, Signature};

pub enum MacroTarget<'a> {
Method(&'a Signature),
Expand All @@ -8,15 +8,15 @@ pub enum MacroTarget<'a> {
pub struct DeriveContext<'a> {
pub generics: &'a Generics,
pub implementation: &'a Path,
pub service: &'a Path,
pub service: Punctuated<Path, Plus>,
target: MacroTarget<'a>,
}

impl<'a> DeriveContext<'a> {
pub fn for_method(
generics: &'a Generics,
implementation: &'a Path,
service: &'a Path,
service: Punctuated<Path, Plus>,
method: &'a Signature,
) -> Self {
Self {
Expand All @@ -30,7 +30,7 @@ impl<'a> DeriveContext<'a> {
pub fn for_struct(
generics: &'a Generics,
implementation: &'a Path,
service: &'a Path,
service: Punctuated<Path, Plus>,
struct_: &'a ItemStruct,
) -> Self {
Self {
Expand All @@ -46,8 +46,12 @@ impl<'a> DeriveContext<'a> {
}

pub fn is_trait(&self) -> bool {
if self.service.len() > 1 {
return true;
}

let impl_ = &self.implementation.segments.last().unwrap().ident;
let struct_ = &self.service.segments.last().unwrap().ident;
let struct_ = &self.service.first().unwrap().segments.last().unwrap().ident;
impl_ != struct_
}
}
Loading