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
//! Request extraction for deserializing request data into application types.
//!
//! Extraction can collect values from multiple request sources, such as path
//! parameters, query strings, headers, cookies, form bodies, and JSON bodies.
//! Define an [`Extractible`] type, then ask the request to build it in a handler:
//!
//! ```
//! # use salvo_core::prelude::*;
//! # use serde::{Deserialize, Serialize};
//! #[derive(Serialize, Deserialize, Extractible, Debug)]
//! // Get the data field value from the body by default.
//! #[salvo(extract(default_source(from = "body")))]
//! struct GoodMan<'a> {
//! /// The id number is obtained from the request path parameter, and the data is automatically parsed as i64 type.
//! #[salvo(extract(source(from = "param")))]
//! id: i64,
//! /// Reference types can be used to avoid memory copying.
//! username: &'a str,
//! first_name: String,
//! last_name: String,
//! }
//!
//! #[handler]
//! async fn edit(req: &mut Request, depot: &mut Depot) {
//! let good_man: GoodMan<'_> = req.extract(depot).await.unwrap();
//! let _ = good_man;
//! }
//! ```
//!
//! Extracted types can be nested. Use `#[salvo(extract(flatten))]` when a nested
//! extractible type should be parsed from the same request. (`#[serde(flatten)]`
//! is not supported on `#[derive(Extractible)]` fields — it conflicts with
//! Salvo's extraction and is rejected at compile time; use the attribute below.)
//!
//! ```
//! # use salvo_core::prelude::*;
//! # use serde::{Deserialize, Serialize};
//! #[derive(Serialize, Deserialize, Extractible, Debug)]
//! #[salvo(extract(default_source(from = "body")))]
//! struct GoodMan<'a> {
//! #[salvo(extract(source(from = "param")))]
//! id: i64,
//! #[salvo(extract(source(from = "query")))]
//! username: &'a str,
//! first_name: String,
//! last_name: String,
//! lovers: Vec<String>,
//! /// The nested field is parsed from the same request.
//! #[salvo(extract(flatten))]
//! nested: Nested<'a>,
//! }
//!
//! #[derive(Serialize, Deserialize, Extractible, Debug)]
//! #[salvo(extract(default_source(from = "body")))]
//! struct Nested<'a> {
//! #[salvo(extract(source(from = "param")))]
//! id: i64,
//! #[salvo(extract(source(from = "query")))]
//! username: &'a str,
//! first_name: String,
//! last_name: String,
//! #[salvo(rename = "lovers")]
//! #[serde(default)]
//! pets: Vec<String>,
//! }
//! ```
//!
//! View the [full nested extraction example] in the repository.
//!
//! [full nested extraction example]: https://github.com/salvo-rs/salvo/blob/main/examples/extract-nested/src/main.rs
/// Metadata types.
pub use Metadata;
use Debug;
pub use RenameRule;
use crate;
use crate::;
/// Describes how to extract a type from a request.
///
/// Implementations provide metadata used by Salvo's extraction machinery and
/// OpenAPI integration, then perform the actual extraction from [`Request`] and
/// [`Depot`].