Skip to content

Commit 8cdfc1c

Browse files
reanme
1 parent 103cdfa commit 8cdfc1c

File tree

3 files changed

+26
-24
lines changed

3 files changed

+26
-24
lines changed

src/lib.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -152,8 +152,10 @@ pub mod trailers;
152152
#[cfg(feature = "hyperium_http")]
153153
mod hyperium_http;
154154

155-
/// Map of arbitrary types to extend the protocol.
156-
pub type Extensions = type_map::concurrent::TypeMap;
155+
/// Map type that allows storing any `Sync + Send + 'static` type as local state
156+
/// on a `Request` or `Response`.
157+
#[doc(inline)]
158+
pub use type_map::concurrent::TypeMap;
157159

158160
// Not public API. Referenced by macro-generated code.
159161
#[doc(hidden)]

src/request.rs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use crate::headers::{
1212
use crate::mime::Mime;
1313
use crate::trailers::{Trailers, TrailersSender};
1414
use crate::Cookie;
15-
use crate::{Body, Extensions, Method, Url, Version};
15+
use crate::{Body, Method, TypeMap, Url, Version};
1616

1717
pin_project_lite::pin_project! {
1818
/// An HTTP request.
@@ -35,7 +35,7 @@ pin_project_lite::pin_project! {
3535
receiver: sync::Receiver<crate::Result<Trailers>>,
3636
#[pin]
3737
body: Body,
38-
extensions: Extensions,
38+
local_state: TypeMap,
3939
}
4040
}
4141

@@ -51,7 +51,7 @@ impl Request {
5151
body: Body::empty(),
5252
sender: Some(sender),
5353
receiver,
54-
extensions: Extensions::new(),
54+
local_state: TypeMap::new(),
5555
}
5656
}
5757

@@ -426,12 +426,12 @@ impl Request {
426426
self.headers.values()
427427
}
428428

429-
/// Returns a reference to the existing extensions.
430-
pub fn extensions(&self) -> &Extensions {
431-
&self.extensions
429+
/// Returns a reference to the existing local state.
430+
pub fn local_state(&self) -> &TypeMap {
431+
&self.local_state
432432
}
433433

434-
/// Returns a mutuable reference to the existing extensions.
434+
/// Returns a mutuable reference to the existing local state.
435435
///
436436
///
437437
/// # Examples
@@ -442,13 +442,13 @@ impl Request {
442442
/// use http_types::{Url, Method, Request, Version};
443443
///
444444
/// let mut req = Request::new(Method::Get, Url::parse("https://example.com")?);
445-
/// req.extensions_mut().insert("hello from the extension");
446-
/// assert_eq!(req.extensions().get(), Some(&"hello from the extension"));
445+
/// req.local_state_mut().insert("hello from the extension");
446+
/// assert_eq!(req.local_state().get(), Some(&"hello from the extension"));
447447
/// #
448448
/// # Ok(()) }
449449
/// ```
450-
pub fn extensions_mut(&mut self) -> &mut Extensions {
451-
&mut self.extensions
450+
pub fn local_state_mut(&mut self) -> &mut TypeMap {
451+
&mut self.local_state
452452
}
453453
}
454454

src/response.rs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use crate::headers::{
1111
};
1212
use crate::mime::Mime;
1313
use crate::trailers::{Trailers, TrailersSender};
14-
use crate::{Body, Cookie, Extensions, StatusCode, Version};
14+
use crate::{Body, Cookie, StatusCode, TypeMap, Version};
1515

1616
pin_project_lite::pin_project! {
1717
/// An HTTP response.
@@ -37,7 +37,7 @@ pin_project_lite::pin_project! {
3737
receiver: sync::Receiver<crate::Result<Trailers>>,
3838
#[pin]
3939
body: Body,
40-
extensions: Extensions,
40+
local_state: TypeMap,
4141
}
4242
}
4343

@@ -52,7 +52,7 @@ impl Response {
5252
body: Body::empty(),
5353
sender: Some(sender),
5454
receiver,
55-
extensions: Extensions::new(),
55+
local_state: TypeMap::new(),
5656
}
5757
}
5858

@@ -392,12 +392,12 @@ impl Response {
392392
self.headers.values()
393393
}
394394

395-
/// Returns a reference to the existing extensions.
396-
pub fn extensions(&self) -> &Extensions {
397-
&self.extensions
395+
/// Returns a reference to the existing local_state.
396+
pub fn local_state(&self) -> &TypeMap {
397+
&self.local_state
398398
}
399399

400-
/// Returns a mutuable reference to the existing extensions.
400+
/// Returns a mutuable reference to the existing local state.
401401
///
402402
///
403403
/// # Examples
@@ -408,13 +408,13 @@ impl Response {
408408
/// use http_types::{StatusCode, Response, Version};
409409
///
410410
/// let mut res = Response::new(StatusCode::Ok);
411-
/// res.extensions_mut().insert("hello from the extension");
412-
/// assert_eq!(res.extensions().get(), Some(&"hello from the extension"));
411+
/// res.local_state_mut().insert("hello from the extension");
412+
/// assert_eq!(res.local_state().get(), Some(&"hello from the extension"));
413413
/// #
414414
/// # Ok(()) }
415415
/// ```
416-
pub fn extensions_mut(&mut self) -> &mut Extensions {
417-
&mut self.extensions
416+
pub fn local_state_mut(&mut self) -> &mut TypeMap {
417+
&mut self.local_state
418418
}
419419
}
420420

0 commit comments

Comments
 (0)