pub struct Path<E> { /* private fields */ }Expand description
Extracts path parameters as cache key parts.
Uses actix-router patterns to match and extract named segments from the request path.
§Type Parameters
E- The inner extractor to chain with. UsePath::newto start a new extractor chain (usesNeutralExtractorinternally), or use thePathExtractorextension 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;
// Extract user_id and post_id from "/users/42/posts/123"
let extractor = Path::new("/users/{user_id}/posts/{post_id}");Using the builder pattern:
use hitbox_http::extractors::{Method, path::PathExtractor};
let extractor = Method::new()
.path("/api/v1/users/{user_id}");§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 |
Implementations§
Source§impl<S> Path<NeutralExtractor<S>>
impl<S> Path<NeutralExtractor<S>>
Sourcepub fn new(resource: &str) -> Self
pub fn new(resource: &str) -> Self
Creates a path extractor that captures named segments from request paths.
Each captured segment becomes a cache key part with the segment name as key. See the struct documentation for pattern syntax.
Chain onto existing extractors using PathExtractor::path instead
if you already have an extractor chain.
Trait Implementations§
Auto Trait Implementations§
impl<E> Freeze for Path<E>where
E: Freeze,
impl<E> RefUnwindSafe for Path<E>where
E: RefUnwindSafe,
impl<E> Send for Path<E>where
E: Send,
impl<E> Sync for Path<E>where
E: Sync,
impl<E> Unpin for Path<E>where
E: Unpin,
impl<E> UnwindSafe for Path<E>where
E: UnwindSafe,
Blanket Implementations§
Source§impl<E> BodyExtractor for Ewhere
E: Extractor,
impl<E> BodyExtractor for Ewhere
E: Extractor,
Source§fn body(self, extraction: BodyExtraction) -> Body<E>
fn body(self, extraction: BodyExtraction) -> Body<E>
Adds body extraction with the specified mode.
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more