mirror of
https://github.com/tokio-rs/axum.git
synced 2026-08-25 00:00:23 +02:00
Avoid double-boxing bodies where possible (#569)
* Avoid double-boxing bodies where possible * Extract `try_downcast` to `util` module
This commit is contained in:
+1
-15
@@ -8,7 +8,7 @@ use crate::{
|
||||
MatchedPath, OriginalUri,
|
||||
},
|
||||
routing::strip_prefix::StripPrefix,
|
||||
util::{ByteStr, PercentDecodedByteStr},
|
||||
util::{try_downcast, ByteStr, PercentDecodedByteStr},
|
||||
BoxError,
|
||||
};
|
||||
use bytes::Bytes;
|
||||
@@ -657,20 +657,6 @@ impl<B, E> Fallback<B, E> {
|
||||
}
|
||||
}
|
||||
|
||||
fn try_downcast<T, K>(k: K) -> Result<T, K>
|
||||
where
|
||||
T: 'static,
|
||||
K: Send + 'static,
|
||||
{
|
||||
use std::any::Any;
|
||||
|
||||
let k = Box::new(k) as Box<dyn Any + Send + 'static>;
|
||||
match k.downcast() {
|
||||
Ok(t) => Ok(*t),
|
||||
Err(other) => Err(*other.downcast().unwrap()),
|
||||
}
|
||||
}
|
||||
|
||||
enum Endpoint<B> {
|
||||
MethodRouter(MethodRouter<B>),
|
||||
Route(Route<B>),
|
||||
|
||||
Reference in New Issue
Block a user