1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
//! Procedural macros for Injectium.
//!
//! This crate provides:
//!
//! - `#[derive(Injectable)]` – implements the [`Injectable`] trait for your
//! structs, automatically pulling each field from the container.
use TokenStream;
use ;
/// Derives an implementation of the `injectium_core::Injectable` trait.
///
/// When applied to a named struct, this macro generates:
///
/// 1. An implementation of `from_container(&Container) -> Self` that clones
/// each field from the container using `container.get::<T>()`.
/// 2. An implementation of `try_from_container(&Container) -> Option<Self>`
/// that uses `container.try_get::<T>()` for graceful missing-dependency
/// handling.
/// 3. A `injectium::declare_dependency!` call for each field type, enabling
/// `Container::validate` to check all dependencies at startup.
///
/// # Requirements
///
/// - The struct must be a named struct (not a tuple struct or enum).
/// - All field types must implement `Clone`.
/// - All field types must be `'static`.
///
/// # Example
///
/// ```ignore
/// use injectium::Injectable;
/// use std::sync::Arc;
///
/// #[derive(Clone, Injectable)]
/// struct Database {
/// conn: Arc<Connection>,
/// }
///
/// #[derive(Injectable)]
/// struct Service {
/// db: Database,
/// }
/// ```