tinc/private/http/
path.rs

1use axum::extract::FromRequestParts;
2use axum::response::IntoResponse;
3
4use crate::__private::HttpErrorResponseCode;
5use crate::__private::error::HttpErrorResponse;
6
7pub async fn deserialize_path<T>(parts: &mut http::request::Parts) -> Result<T, axum::response::Response>
8where
9    T: serde::de::DeserializeOwned + Send,
10{
11    match axum::extract::Path::<T>::from_request_parts(parts, &()).await {
12        Ok(axum::extract::Path(value)) => Ok(value),
13        Err(err) => Err(HttpErrorResponse {
14            code: HttpErrorResponseCode::InvalidArgument,
15            details: Default::default(),
16            message: &format!("invalid path: {err}"),
17        }
18        .into_response()),
19    }
20}