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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
//! Procedural macros for [`rust-dix`](https://docs.rs/rust-dix)
//! (`rust-dix-macros`).
//!
//! This crate is an implementation detail of `rust-dix`; depend on
//! `rust-dix`, which re-exports these macros (do not depend on this crate
//! directly unless you have a specific reason).
//!
//! # Macros
//!
//! - [`macro@Inject`] — `#[derive(Inject)]` generates constructor injection
//! code from struct fields (fields marked `#[inject]`,
//! `#[inject(owned)]`, `#[inject(provider)]`, `#[inject(key = <expr>)]` or
//! `#[inject(owned, key = <expr>)]`). Key expressions accept string literals,
//! typed `ServiceKey` values, or downstream key types implementing
//! `From<LocalKey> for ServiceKey` (extension path instead of duplicating
//! macros). `#[inject(provider)]` cannot be combined with `key`
//! (compile error; resolve through the injected provider instead).
//! - [`macro@inject`] — attribute macro placed on structs or trait impls to
//! auto-register services with the container.
//! - [`macro@module`] — compile-time module scan that collects
//! `register!()` declarations.
//! - [`macro@register`] — function-like placeholder used inside
//! `#[rust_dix::module]`.
//!
//! # Example
//!
//! Illustrative only (the macros generate code that references `rust_dix`, so
//! this proc-macro crate's doctests cannot link the core crate; the same
//! patterns are compiled in `rust-dix`' test suite):
//!
//! ```rust,ignore
//! use rust_dix::{inject, Inject};
//! use std::sync::Arc;
//!
//! struct Config;
//! trait IWorker: Send + Sync {}
//!
//! #[derive(Inject)]
//! struct Worker {
//! #[inject]
//! config: Arc<Config>,
//! }
//!
//! #[inject(singleton)]
//! impl IWorker for Worker {}
//! ```
//!
//! # Engineering baseline
//!
//! MSRV **Rust 1.95**; `#![forbid(unsafe_code)]`; errors are emitted as
//! compile errors instead of panics where possible. See the
//! [repository security policy](https://github.com/Rust-Framework/rust-dix/blob/main/SECURITY.md).
use TokenStream;
use quote;
use parse_macro_input;
// ───────────────────────────────────────────────────────────────────────────
// #[derive(Inject)] — auto-generate constructor from struct fields
// ───────────────────────────────────────────────────────────────────────────
// ───────────────────────────────────────────────────────────────────────────
// register!() — function-like placeholder macro for use inside #[module]
// ───────────────────────────────────────────────────────────────────────────
// ───────────────────────────────────────────────────────────────────────────
// #[module] — compile-time module scanning for register!() declarations
// ───────────────────────────────────────────────────────────────────────────
// ───────────────────────────────────────────────────────────────────────────
// #[inject] — attribute macro for auto-registration
// ───────────────────────────────────────────────────────────────────────────