pavex/request/path/
mod.rs

1//! Extract data from the URL of incoming requests.
2//!
3//! # Overview
4//!
5//! When it comes to route information, there are two important extractors to be aware of:
6//!
7//! - [`PathParams`]: extract path parameters from the URL of incoming requests
8//! - [`MatchedPathPattern`]: extract the route template that matched for the incoming request
9//!
10//! Check out their documentation for more details.
11//!
12//! # Example: path parameters
13//!
14//! ```rust
15//! use pavex::{get, request::path::PathParams};
16//!
17//! // Define a route with a path parameter, `{home_id}`.
18//! // The `PathParams` extractor deserializes the extracted path parameters into
19//! // the type you specified—`Home` in this case.
20//! #[get(path = "/home/{home_id}")]
21//! pub fn get_home(params: &PathParams<Home>) -> String {
22//!    format!("The identifier for this home is: {}", params.0.home_id)
23//! }
24//!
25//! // The PathParams attribute macro derives the necessary (de)serialization traits.
26//! #[PathParams]
27//! pub struct Home {
28//!     // The name of the field must match the name of the path parameter
29//!     // used in the route definition.
30//!     home_id: u32
31//! }
32//! ```
33//!
34//! Check out [`PathParams`]' documentation for more details.
35//!
36//! [`PathParams`]: struct@PathParams
37
38pub use matched_path::MatchedPathPattern;
39pub use path_params::PathParams;
40/// Derive (de)serialization logic for a type that is going to be used to extract path parameters.
41///
42/// This macro derives [`StructuralDeserialize`], [`serde::Serialize`] and [`serde::Deserialize`]
43/// for the type that it is applied to.
44///
45/// Check out [`PathParams`](struct@PathParams) for more details on how to work with
46/// path parameters in Pavex.
47/// Check out [`StructuralDeserialize`] if you are curious about the rationale behind this
48/// macro.
49///
50/// # Example
51///
52/// ```rust
53/// use pavex::{get, request::path::PathParams};
54///
55/// // Define a route with a path parameter, `{home_id}`.
56/// #[get(path = "/home/{home_id}")]
57/// pub fn get_home(params: &PathParams<Home>) -> String {
58///    format!("The identifier for this home is: {}", params.0.home_id)
59/// }
60///
61/// // The PathParams attribute macro derives the necessary (de)serialization traits.
62/// #[PathParams]
63/// pub struct Home {
64///     // The name of the field must match the name of the path parameter
65///     // used in the route definition.
66///     home_id: u32
67/// }
68/// ```
69///
70/// [`StructuralDeserialize`]: crate::serialization::StructuralDeserialize
71pub use pavex_macros::PathParams;
72pub use raw_path_params::{EncodedParamValue, RawPathParams, RawPathParamsIter};
73
74mod deserializer;
75pub mod errors;
76
77mod matched_path;
78mod path_params;
79mod raw_path_params;