axum_handler_extract/
matched_path.rs1use axum::{
2 extract::{rejection::MatchedPathRejection, MatchedPath},
3 http::{Extensions as HttpExtensions, Request as HttpRequest},
4};
5
6use crate::{extensions_extract_from_request, extract_from_extensions};
7
8pub async fn matched_path_from_request<B>(
10 req: HttpRequest<B>,
11) -> Result<(Option<MatchedPath>, HttpRequest<B>), (MatchedPathRejection, HttpRequest<B>)> {
12 let (matched_path, req) = extensions_extract_from_request(req).await;
13 match matched_path {
14 Ok(x) => Ok((Some(x), req)),
15 Err(MatchedPathRejection::MatchedPathMissing(_)) => Ok((None, req)),
16 Err(err) => Err((err, req)),
17 }
18}
19
20pub async fn matched_path_from_extensions(
22 extensions: HttpExtensions,
23) -> Result<(Option<MatchedPath>, HttpExtensions), (MatchedPathRejection, HttpExtensions)> {
24 let (matched_path, extensions) = extract_from_extensions(extensions).await;
25 match matched_path {
26 Ok(x) => Ok((Some(x), extensions)),
27 Err(MatchedPathRejection::MatchedPathMissing(_)) => Ok((None, extensions)),
28 Err(err) => Err((err, extensions)),
29 }
30}