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
use ResourceDef;
use async_trait;
use ;
use NeutralExtractor;
use crateCacheableHttpRequest;
/// Extracts path parameters as cache key parts.
///
/// Uses [actix-router](https://docs.rs/actix-router) patterns to match and
/// extract named segments from the request path.
///
/// # Type Parameters
///
/// * `E` - The inner extractor to chain with. Use [`Path::new`] to start
/// a new extractor chain (uses [`NeutralExtractor`] internally), or use the
/// [`PathExtractor`] extension trait to chain onto an existing extractor.
///
/// # Pattern Syntax
///
/// - `{name}` — captures a path segment (characters until `/`)
/// - `{name:regex}` — captures with regex constraint (e.g., `{id:\d+}`)
/// - `{tail}*` — captures remaining path (e.g., `/blob/{path}*` matches `/blob/a/b/c`)
///
/// # Examples
///
/// ```
/// use hitbox_http::extractors::Path;
///
/// # use bytes::Bytes;
/// # use http_body_util::Empty;
/// # use hitbox_http::extractors::NeutralExtractor;
/// // Extract user_id and post_id from "/users/42/posts/123"
/// let extractor = Path::new("/users/{user_id}/posts/{post_id}");
/// # let _: &Path<NeutralExtractor<Empty<Bytes>>> = &extractor;
/// ```
///
/// Using the builder pattern:
///
/// ```
/// use hitbox_http::extractors::{Method, path::PathExtractor};
///
/// # use bytes::Bytes;
/// # use http_body_util::Empty;
/// # use hitbox_http::extractors::{NeutralExtractor, Path};
/// let extractor = Method::new()
/// .path("/api/v1/users/{user_id}");
/// # let _: &Path<Method<NeutralExtractor<Empty<Bytes>>>> = &extractor;
/// ```
///
/// # Key Parts Generated
///
/// For path `/users/42/posts/123` with pattern `/users/{user_id}/posts/{post_id}`:
/// - `KeyPart { key: "user_id", value: Some("42") }`
/// - `KeyPart { key: "post_id", value: Some("123") }`
///
/// # Format Examples
///
/// | Request Path | Pattern | Generated Key Parts |
/// |--------------|---------|---------------------|
/// | `/users/42` | `/users/{id}` | `id=42` |
/// | `/api/v2/items` | `/api/{version}/items` | `version=v2` |
/// | `/files/docs/report.pdf` | `/files/{path}*` | `path=docs/report.pdf` |
/// | `/orders/123/items/456` | `/orders/{order_id}/items/{item_id}` | `order_id=123&item_id=456` |
/// Extension trait for adding path extraction to an extractor chain.
///
/// # For Callers
///
/// Chain this to extract named segments from the request path. Each captured
/// segment becomes a cache key part. Use patterns like `/users/{user_id}` to
/// capture dynamic path segments.
///
/// # For Implementors
///
/// This trait is automatically implemented for all [`Extractor`]
/// types. You don't need to implement it manually.