File tree Expand file tree Collapse file tree 1 file changed +7
-8
lines changed Expand file tree Collapse file tree 1 file changed +7
-8
lines changed Original file line number Diff line number Diff line change 1- use axum:: extract:: { Extension , FromRequestParts } ;
1+ use axum:: extract:: FromRequestParts ;
22use http:: request:: Parts ;
33
44/// Cache results of other extractors.
@@ -88,13 +88,12 @@ where
8888 type Rejection = T :: Rejection ;
8989
9090 async fn from_request_parts ( parts : & mut Parts , state : & S ) -> Result < Self , Self :: Rejection > {
91- match Extension :: < CachedEntry < T > > :: from_request_parts ( parts, state) . await {
92- Ok ( Extension ( CachedEntry ( value) ) ) => Ok ( Self ( value) ) ,
93- Err ( _) => {
94- let value = T :: from_request_parts ( parts, state) . await ?;
95- parts. extensions . insert ( CachedEntry ( value. clone ( ) ) ) ;
96- Ok ( Self ( value) )
97- }
91+ if let Some ( value) = parts. extensions . get :: < CachedEntry < T > > ( ) {
92+ Ok ( Self ( value. 0 . clone ( ) ) )
93+ } else {
94+ let value = T :: from_request_parts ( parts, state) . await ?;
95+ parts. extensions . insert ( CachedEntry ( value. clone ( ) ) ) ;
96+ Ok ( Self ( value) )
9897 }
9998 }
10099}
You can’t perform that action at this time.
0 commit comments