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
//! # Astrea - File-based Router for Axum
//!
//! / # Astrea - 基于 Axum 的文件路由器
//!
//! Astrea is a file-system based router for Axum, inspired by [Nitro] and [H3].
//!
//! Astrea 是一个受 [Nitro] 和 [H3] 启发的 Axum 文件路由器。
//!
//! ## Features
//!
//! ## 特性
//!
//! - **Simple unified handler signature** - All handlers follow the same pattern:
//! `async fn handler(event: Event) -> Result<Response>`
//! **简单统一的处理函数签名** - 所有处理函数遵循相同模式:
//! `async fn handler(event: Event) -> Result<Response>`
//!
//! - **Declarative parameter extraction** - Access request data through helper functions
//! instead of complex Axum extractor signatures
//! **声明式参数提取** - 通过辅助函数访问请求数据,无需复杂的 Axum 提取器签名
//!
//! - **File-based routing** - Routes are automatically generated from your filesystem
//! structure at compile time
//! **基于文件的路由** - 在编译时根据文件系统结构自动生成路由
//!
//! - **Type-safe** - Full Rust type safety with compile-time route generation
//! **类型安全** - 完整的 Rust 类型安全,编译时生成路由
//!
//! - **Axum ecosystem compatible** - Works seamlessly with Axum middleware
//! **兼容 Axum 生态** - 与 Axum 中间件无缝协作
//!
//! ## Quick Start
//!
//! ## 快速开始
//!
//! ```rust,no_run
//! use astrea::prelude::*;
//! use serde_json::json;
//!
//! // routes/index.get.rs
//! #[route]
//! async fn handler(event: Event) -> Result<Response> {
//! let name = get_param(&event, "name").unwrap_or("World");
//! json(json!({ "message": format!("Hello, {}!", name) }))
//! }
//! ```
//!
//! ## Route File Convention
//!
//! ## 路由文件规则
//!
//! Routes are generated from the `routes/` directory:
//!
//! 路由从 `routes/` 目录生成:
//!
//! - `routes/index.get.rs` → `GET /`
//! - `routes/users.get.rs` → `GET /users`
//! - `routes/users/[id].get.rs` → `GET /users/:id`
//! - `routes/posts/[...slug].get.rs` → `GET /posts/*slug`
//!
//! ## Module Organization
//!
//! ## 模块组织
//!
//! - [`event`] - Request event type that encapsulates all request data
//! [`event`] - 封装所有请求数据的请求事件类型
//! - [`extract`] - Helper functions for extracting request data
//! [`extract`] - 提取请求数据的辅助函数
//! - [`response`] - Response builders and helpers
//! [`response`] - 响应构建器和辅助函数
//! - [`error`] - Error types and result handling
//! [`error`] - 错误类型和结果处理
//!
//! [Nitro]: https://nitro.unjs.io/
//! [H3]: https://h3.unjs.io/
// ============================================================================
// Re-export dependencies - users don't need to depend on these crates directly
// ============================================================================
// Re-export 依赖库 — 用户无需在 Cargo.toml 中直接依赖这些 crate
// ============================================================================
/// Re-export of `axum` - users don't need to explicitly depend on it
/// / Re-export axum — 用户无需显式依赖
pub use axum;
/// Re-export of `bytes`
/// / Re-export bytes
pub use bytes;
/// Re-export of `comfy-table` - used by route macros
/// / Re-export comfy-table - 由路由宏使用
pub use comfy_table;
/// Re-export of `serde`
/// / Re-export serde
pub use serde;
/// Re-export of `serde_json`
/// / Re-export serde_json
pub use serde_json;
/// Re-export of `tokio`
/// / Re-export tokio
pub use tokio;
/// Re-export of `tower`
/// / Re-export tower
pub use tower;
/// Re-export of `tower_http`
/// / Re-export tower_http
pub use tower_http;
/// Re-export of `tracing`
/// / Re-export tracing
pub use tracing;
/// Re-export of `tokio-stream` - used by SSE macro code
/// / Re-export tokio-stream - 由 SSE 宏代码使用
pub use tokio_stream;
// Convenience re-export: axum::serve
// 便捷 re-export: axum::serve
pub use serve;
// Re-export commonly used types
// 重新导出常用类型
pub use RouteError;
pub use Event;
pub use Response;
// Re-export procedural macros
// 重新导出过程宏
pub use generate_routes;
/// Prelude module with common imports
///
/// / 包含常用导入的预导出模块
///
/// # Example
///
/// # 示例
///
/// ```rust,ignore
/// use astrea::prelude::*;
/// ```