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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
use FromDeriveInput;
use TokenStream;
use quote;
use ;
use crateGenerator;
use crateSource;
/// Derive macro for `KeyExtract` trait.
///
/// Generates an implementation of `KeyExtract` that creates key parts from struct fields.
///
/// # Attributes
///
/// - `#[key_extract(name = "...")]` - Override the key part name (default: field name)
/// - `#[key_extract(skip)]` - Skip this field in key generation
///
/// # Example
///
/// ```ignore
/// use hitbox_fn::KeyExtract;
///
/// #[derive(KeyExtract)]
/// struct UserRequest {
/// user_id: u64,
/// #[key_extract(skip)]
/// password: String,
/// }
/// ```
/// Attribute macro for caching async functions.
///
/// Transforms an async function to return a builder that can be configured with
/// backend and policy before execution.
///
/// # Attributes
///
/// - `prefix = "..."` - Custom prefix for the cache key (default: function name)
///
/// # Example
///
/// ```ignore
/// use hitbox_fn::cached;
///
/// #[cached]
/// async fn fetch_user(id: UserId, tenant: TenantId) -> Result<User, Error> {
/// // expensive operation
/// }
///
/// // With custom prefix
/// #[cached(prefix = "user_data")]
/// async fn fetch_user(id: UserId) -> Result<User, Error> {
/// // expensive operation
/// }
///
/// // Zero-argument function
/// #[cached(prefix = "app_config")]
/// async fn get_config() -> Result<Config, Error> {
/// // expensive operation
/// }
///
/// // Usage with pre-configured cache
/// let cache = Cache::builder()
/// .backend(backend)
/// .policy(policy)
/// .build();
///
/// let user = fetch_user(UserId(42), TenantId("acme".into()))
/// .cache(&cache)
/// .await?;
///
/// // Usage with context
/// let (user, ctx) = fetch_user(UserId(42), TenantId("acme".into()))
/// .cache(&cache)
/// .with_context()
/// .await;
/// println!("Cache status: {:?}", ctx.status);
///
/// // Usage with inline configuration
/// let user = fetch_user(UserId(42), TenantId("acme".into()))
/// .backend(backend)
/// .policy(policy)
/// .await?;
/// ```
/// Derive macro for `CacheableResponse` trait.
///
/// Generates an implementation of `CacheableResponse` where the type is cached as itself.
/// The type must implement `Clone + Serialize + DeserializeOwned + Send + 'static`.
///
/// # Example
///
/// ```ignore
/// use hitbox_derive::CacheableResponse;
/// use serde::{Deserialize, Serialize};
///
/// #[derive(Clone, Serialize, Deserialize, CacheableResponse)]
/// struct User {
/// id: u64,
/// name: String,
/// }
///
/// // Now User can be used as a return type in cached functions:
/// #[cached]
/// async fn fetch_user(id: u64) -> Result<User, Error> {
/// // ...
/// }
/// ```
/// Derive macro for `CacheableRequest` trait.
///
/// Generates an implementation of `CacheableRequest` with standard cache policy logic.
/// The type can then participate in the hitbox caching pipeline.
///
/// # Example
///
/// ```ignore
/// use hitbox_derive::CacheableRequest;
///
/// #[derive(CacheableRequest)]
/// struct SearchRequest {
/// query: String,
/// page: u32,
/// }
/// ```