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;
4
4
use async_std:: io:: { self , prelude:: * , BufReader } ;
5
5
use async_std:: task:: { Context , Poll } ;
6
6
7
+ use std:: ops:: Index ;
7
8
use std:: pin:: Pin ;
8
9
use std:: { str:: FromStr , sync:: Arc } ;
9
10
@@ -377,6 +378,34 @@ impl<'a, State> IntoIterator for &'a mut Request<State> {
377
378
}
378
379
}
379
380
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
+
380
409
pub ( crate ) fn rest ( route_params : & [ Params ] ) -> Option < & str > {
381
410
route_params
382
411
. last ( )
Original file line number Diff line number Diff line change 1
1
use async_std:: io:: prelude:: * ;
2
2
use std:: convert:: TryFrom ;
3
+ use std:: ops:: Index ;
3
4
4
5
use mime:: Mime ;
5
6
use serde:: Serialize ;
@@ -324,3 +325,31 @@ impl<'a> IntoIterator for &'a mut Response {
324
325
self . res . iter_mut ( )
325
326
}
326
327
}
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