Expand description
Shaku is a compile time dependency injection library. It can be used directly or through
integration with application frameworks such as Rocket (see
shaku_rocket
).
§Getting started
See the getting started guide
§Crate features
By default shaku is thread-safe and exposes macros, but these can be disabled by opting out of the following features:
thread_safe
: Requires components to beSend + Sync
derive
: Uses theshaku_derive
crate to provide proc-macro derives ofComponent
andProvider
, and themodule
macro.
Modules§
- guide
- Getting started guide
Macros§
Structs§
- Module
Build Context - Builds a
Module
and its associated components. Build context, such as parameters and resolved components, are stored in this struct. - Module
Builder - Builds a
Module
. Component parameters can be set, and both components and providers implementations can be overridden.
Traits§
- Component
- Components provide a service by implementing an interface. They may use other components as dependencies.
- HasComponent
- Indicates that a module contains a component which implements the interface.
- HasProvider
- Indicates that a module contains a provider which implements the interface.
- Interface
- Interfaces must be
'static
in order to be stored in a module (hence theAny
requirement). - Module
- A module represents a group of services. By implementing traits such as
HasComponent
on a module, service dependencies are checked at compile time. At runtime, modules hold the components they are associated with. - Module
Interface - Submodules must be
'static
in order to be stored in other modules (hence theAny
requirement). - Provider
- Like
Component
s, providers provide a service by implementing an interface.
Type Aliases§
- Component
Fn - The type signature of
Component::build
without the parameters. This is used when overriding a component viaModuleBuilder::with_component_override_fn
- Provider
Fn - The type signature of
Provider::provide
. This is used when overriding a provider viaModuleBuilder::with_provider_override