ferrunix/
lib.rs

1#![cfg_attr(
2    feature = "multithread",
3    doc = "_You're viewing the documentation with the **`multithread` feature** turned on._\n\n"
4)]
5#![cfg_attr(
6    feature = "tokio",
7    doc = "_You're viewing the documentation with the **`tokio` feature** turned on._\n\n"
8)]
9#![cfg_attr(
10    all(not(feature = "tokio"), not(feature = "multithread")),
11    doc = "#### _You're viewing the documentation with **`no features`** turned on._\n\n"
12)]
13//! # Ferrunix
14//!
15//! A simple, idiomatic, and lightweight [dependency injection] framework for Rust.
16//!
17//! **For a comprehensive introduction check out the [user guide].**
18//!
19//! ## Documentation
20//!
21//! Due to how the various features affect the public API of the library, the
22//! documentation is provided seperately for each major feature.
23//!
24//! _Documentation on [docs.rs] is compiled with the `multithread` feature turned on_
25//!
26//! |    Feature Flags    | Link to Documentation |
27//! | ------------------- | --------------------- |
28//! | `none`              | [link to docs](https://leandros.github.io/ferrunix/docs-default/ferrunix/)     |
29//! | `multithread`       | [link to docs](https://leandros.github.io/ferrunix/docs-multithread/ferrunix/) |
30//! | `tokio`             | [link to docs](https://leandros.github.io/ferrunix/docs-multithread/ferrunix/) |
31//!
32//! ## Getting Started
33//!
34//! The easiest way to get started is with the multi-threaded registry, and the derive macro,
35//! you can enable this as follows:
36//!
37//! ```toml
38//! [dependencies]
39//! ferrunix = { version = "0.5", features = ["multithread"] }
40//! ```
41//!
42//! ## Cargo Feature Flags
43//!
44//! Ferrunix has the following [features] to enable further functionality.
45//! Features enabled by default are marked with `*`.
46//!
47//! - `multithread`: Enables support for accessing the registry from multiple
48//!     threads. This adds a bound that all registered types must be `Send`.
49//! - `derive` (`*`): Enables support for the `#[derive(Inject)]` macro.
50//! - `tokio`: Enables support for `async` constructors. Bumps the MSRV up to
51//!     `1.75.0` because some of the internal traits require [RPITIT].
52//! - `tracing`: Enables support for [tracing] and annotates all public functions with
53//!     [`tracing::instrument`].
54//!
55//! [dependency injection]: https://en.wikipedia.org/wiki/Dependency_injection
56//! [docs.rs]: https://docs.rs/ferrunix
57//! [user guide]: https://leandros.github.io/ferrunix/user-guide/first-steps.html
58//! [RPITIT]: https://blog.rust-lang.org/2023/12/21/async-fn-rpit-in-traits.html#whats-stabilizing
59//! [features]: https://doc.rust-lang.org/cargo/reference/manifest.html#the-features-section
60//! [tracing]: https://docs.rs/tracing/latest/tracing/index.html
61//! [`tracing::instrument`]: https://docs.rs/tracing/latest/tracing/attr.instrument.html
62
63pub use ferrunix_core::dependencies;
64pub use ferrunix_core::dependency_builder;
65pub use ferrunix_core::registry;
66pub use ferrunix_core::types;
67pub use ferrunix_core::error;
68
69pub use dependencies::Singleton;
70pub use dependencies::Transient;
71pub use registry::Registry;
72
73#[cfg(feature = "derive")]
74pub use ferrunix_macros::Inject;
75
76/// Register a [`RegistrationFunc`]. Usually invoked by the derive macro.
77///
78pub use ferrunix_core::registration::autoregister;
79pub use ferrunix_core::registration::RegistrationFunc;
80
81pub use ferrunix_core::types::Ref;