File tree Expand file tree Collapse file tree 2 files changed +58
-0
lines changed Expand file tree Collapse file tree 2 files changed +58
-0
lines changed Original file line number Diff line number Diff line change @@ -4,6 +4,7 @@ use serde::Deserialize;
44use async_std:: io:: { self , prelude:: * , BufReader } ;
55use async_std:: task:: { Context , Poll } ;
66
7+ use std:: ops:: Index ;
78use std:: pin:: Pin ;
89use std:: { str:: FromStr , sync:: Arc } ;
910
@@ -377,6 +378,34 @@ impl<'a, State> IntoIterator for &'a mut Request<State> {
377378 }
378379}
379380
381+ impl < State > Index < HeaderName > for Request < State > {
382+ type Output = HeaderValues ;
383+
384+ /// Returns a reference to the value corresponding to the supplied name.
385+ ///
386+ /// # Panics
387+ ///
388+ /// Panics if the name is not present in `Request`.
389+ #[ inline]
390+ fn index ( & self , name : HeaderName ) -> & HeaderValues {
391+ & self . request [ name]
392+ }
393+ }
394+
395+ impl < State > Index < & str > for Request < State > {
396+ type Output = HeaderValues ;
397+
398+ /// Returns a reference to the value corresponding to the supplied name.
399+ ///
400+ /// # Panics
401+ ///
402+ /// Panics if the name is not present in `Request`.
403+ #[ inline]
404+ fn index ( & self , name : & str ) -> & HeaderValues {
405+ & self . request [ name]
406+ }
407+ }
408+
380409pub ( crate ) fn rest ( route_params : & [ Params ] ) -> Option < & str > {
381410 route_params
382411 . last ( )
Original file line number Diff line number Diff line change 11use async_std:: io:: prelude:: * ;
22use std:: convert:: TryFrom ;
3+ use std:: ops:: Index ;
34
45use mime:: Mime ;
56use serde:: Serialize ;
@@ -324,3 +325,31 @@ impl<'a> IntoIterator for &'a mut Response {
324325 self . res . iter_mut ( )
325326 }
326327}
328+
329+ impl Index < HeaderName > for Response {
330+ type Output = HeaderValues ;
331+
332+ /// Returns a reference to the value corresponding to the supplied name.
333+ ///
334+ /// # Panics
335+ ///
336+ /// Panics if the name is not present in `Response`.
337+ #[ inline]
338+ fn index ( & self , name : HeaderName ) -> & HeaderValues {
339+ & self . res [ name]
340+ }
341+ }
342+
343+ impl Index < & str > for Response {
344+ type Output = HeaderValues ;
345+
346+ /// Returns a reference to the value corresponding to the supplied name.
347+ ///
348+ /// # Panics
349+ ///
350+ /// Panics if the name is not present in `Response`.
351+ #[ inline]
352+ fn index ( & self , name : & str ) -> & HeaderValues {
353+ & self . res [ name]
354+ }
355+ }
You can’t perform that action at this time.
0 commit comments