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
//! Extract data from the URL of incoming requests.
//!
//! # Overview
//!
//! When it comes to route information, there are two important extractors to be aware of:
//!
//! - [`PathParams`]: extract path parameters from the URL of incoming requests
//! - [`MatchedPathPattern`]: extract the route template that matched for the incoming request
//!
//! Check out their documentation for more details.
//!
//! # Example: path parameters
//!
//! ```rust
//! use pavex::{get, request::path::PathParams};
//!
//! // Define a route with a path parameter, `{home_id}`.
//! // The `PathParams` extractor deserializes the extracted path parameters into
//! // the type you specified—`Home` in this case.
//! #[get(path = "/home/{home_id}")]
//! pub fn get_home(params: &PathParams<Home>) -> String {
//! format!("The identifier for this home is: {}", params.0.home_id)
//! }
//!
//! // The PathParams attribute macro derives the necessary (de)serialization traits.
//! #[PathParams]
//! pub struct Home {
//! // The name of the field must match the name of the path parameter
//! // used in the route definition.
//! home_id: u32
//! }
//! ```
//!
//! Check out [`PathParams`]' documentation for more details.
//!
//! [`PathParams`]: struct@PathParams
pub use MatchedPathPattern;
pub use PathParams;
/// Derive (de)serialization logic for a type that is going to be used to extract path parameters.
///
/// This macro derives [`StructuralDeserialize`], [`serde::Serialize`] and [`serde::Deserialize`]
/// for the type that it is applied to.
///
/// Check out [`PathParams`](struct@PathParams) for more details on how to work with
/// path parameters in Pavex.
/// Check out [`StructuralDeserialize`] if you are curious about the rationale behind this
/// macro.
///
/// # Example
///
/// ```rust
/// use pavex::{get, request::path::PathParams};
///
/// // Define a route with a path parameter, `{home_id}`.
/// #[get(path = "/home/{home_id}")]
/// pub fn get_home(params: &PathParams<Home>) -> String {
/// format!("The identifier for this home is: {}", params.0.home_id)
/// }
///
/// // The PathParams attribute macro derives the necessary (de)serialization traits.
/// #[PathParams]
/// pub struct Home {
/// // The name of the field must match the name of the path parameter
/// // used in the route definition.
/// home_id: u32
/// }
/// ```
///
/// [`StructuralDeserialize`]: crate::serialization::StructuralDeserialize
pub use PathParams;
pub use ;