1#![doc = include_str!("README.md")]
2#![cfg_attr(docsrs, feature(doc_cfg))]
3
4use cfg_if::cfg_if;
5use std::any::Any;
6
7cfg_if! {
14 if #[cfg(feature = "async")] {
15 pub type Ref<T> = std::sync::Arc<T>;
17
18 #[doc(hidden)]
20 pub type Mut<T> = std::sync::RwLock<T>;
21
22 pub type ServiceFactory = dyn (Fn(&ServiceProvider) -> Ref<dyn Any + Send + Sync>) + Send + Sync;
24 } else {
25 pub type Ref<T> = std::rc::Rc<T>;
27
28 #[doc(hidden)]
30 pub type Mut<T> = std::cell::RefCell<T>;
31
32 pub type ServiceFactory = dyn Fn(&ServiceProvider) -> Ref<dyn Any>;
34 }
35}
36
37pub type RefMut<T> = Ref<Mut<T>>;
39
40mod collection;
41mod dependency;
42mod description;
43pub(crate) mod fmt;
44mod keyed;
45mod provider;
46mod r#type;
47mod validation;
48
49pub use collection::ServiceCollection;
50pub use dependency::{ServiceCardinality, ServiceDependency};
51pub use description::{ServiceDescriptor, ServiceLifetime};
52pub use keyed::{KeyedRef, KeyedRefMut};
53pub use provider::{ScopedServiceProvider, ServiceProvider};
54pub use r#type::Type;
55pub use validation::{validate, ValidationError};
56
57cfg_if! {
58 if #[cfg(feature = "builder")] {
59 mod builder;
60
61 #[cfg_attr(docsrs, doc(cfg(feature = "builder")))]
62 pub use builder::{
63 exactly_one, exactly_one_with_key, existing, existing_as_self, existing_with_key, existing_with_key_as_self,
64 scoped, scoped_factory, scoped_with_key, scoped_with_key_factory, singleton, singleton_as_self,
65 singleton_factory, singleton_with_key, singleton_with_key_factory, transient, transient_as_self,
66 transient_factory, transient_with_key, transient_with_key_as_self, transient_with_key_factory, zero_or_more,
67 zero_or_more_with_key, zero_or_one, zero_or_one_with_key,
68 };
69
70 #[cfg_attr(docsrs, doc(cfg(feature = "builder")))]
71 pub use description::ServiceDescriptorBuilder;
72 }
73}
74
75cfg_if! {
76 if #[cfg(feature = "inject")] {
77 mod activator;
78 mod inject;
79
80 #[cfg_attr(docsrs, doc(cfg(feature = "inject")))]
81 pub use activator::Activator;
82
83 #[cfg_attr(docsrs, doc(cfg(feature = "inject")))]
84 pub use inject::{InjectBuilder, Injectable, inject, injectable};
85 }
86}
87
88#[cfg(feature = "lazy")]
90pub mod lazy;
91
92#[cfg(test)]
93mod test;