Skip to main content

sova_core/extract/
path.rs

1use super::{params_as, FromRequestParts};
2use crate::error::Result;
3use crate::request::Request;
4use serde::de::DeserializeOwned;
5
6/// Path parameters deserialized into `T` (e.g. `struct Id { id: String }` for `/:id`).
7#[derive(Debug, Clone)]
8pub struct Path<T>(pub T);
9
10impl<T> Path<T> {
11    pub fn into_inner(self) -> T {
12        self.0
13    }
14}
15
16impl<T> std::ops::Deref for Path<T> {
17    type Target = T;
18    fn deref(&self) -> &Self::Target {
19        &self.0
20    }
21}
22
23impl<T: DeserializeOwned + Send> FromRequestParts for Path<T> {
24    fn from_request_parts(req: &Request) -> Result<Self> {
25        Ok(Path(params_as(req)?))
26    }
27}