Skip to content

Commit

Permalink
Merge pull request #539 from bluk/update-local-to-ext
Browse files Browse the repository at this point in the history
Update docs from Request.local to Request.ext
  • Loading branch information
yoshuawuyts authored May 28, 2020
2 parents 4394b49 + 31c974a commit fd2a545
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 18 deletions.
16 changes: 10 additions & 6 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,10 +104,14 @@
//!
//! ## State
//!
//! Middleware often needs to share values with the endpoint. This is done through "local state".
//! Local state is built using a typemap that's available through [`Request::local`].
//! Middleware often needs to share values with the endpoint. This is done through "request scoped
//! state". Request scoped state is built using a typemap that's available through
//! [`Request::ext`].
//!
//! Global state is used when a complete application needs access to a particular
//! If the endpoint needs to share values with middleware, response scoped state can be set via
//! [`Response::set_ext`] and is available through [`Response::ext`].
//!
//! Application scoped state is used when a complete application needs access to a particular
//! value. Examples of this include: database connections, websocket connections, or
//! network-enabled config. Every `Request<State>` has an inner value that must
//! implement `Send + Sync + Clone`, and can thus freely be shared between requests.
Expand All @@ -117,7 +121,7 @@
//!
//! ## Extension Traits
//!
//! Sometimes having global and local context can require a bit of setup. There are
//! Sometimes having application and request scoped context can require a bit of setup. There are
//! cases where it'd be nice if things were a little easier. This is why Tide
//! encourages people to write _extension traits_.
//!
Expand Down Expand Up @@ -236,9 +240,9 @@ pub fn new() -> server::Server<()> {
Server::new()
}

/// Create a new Tide server with shared global state.
/// Create a new Tide server with shared application scoped state.
///
/// Global state is useful for storing items
/// Application scoped state is useful for storing items
///
/// # Examples
///
Expand Down
2 changes: 1 addition & 1 deletion src/request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ impl<State> Request<State> {
}

#[must_use]
/// Access app-global state.
/// Access application scoped state.
pub fn state(&self) -> &State {
&self.state
}
Expand Down
4 changes: 2 additions & 2 deletions src/response.rs
Original file line number Diff line number Diff line change
Expand Up @@ -238,13 +238,13 @@ impl Response {
self.cookie_events.push(CookieEvent::Removed(cookie));
}

/// Get a response extension value.
/// Get a response scoped extension value.
#[must_use]
pub fn ext<T: Send + Sync + 'static>(&self) -> Option<&T> {
self.res.ext().get()
}

/// Set a local value.
/// Set a response scoped extension value.
pub fn set_ext<T: Send + Sync + 'static>(mut self, val: T) -> Self {
self.res.ext_mut().insert(val);
self
Expand Down
17 changes: 8 additions & 9 deletions src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -163,9 +163,9 @@ impl Default for Server<()> {
}

impl<State: Send + Sync + 'static> Server<State> {
/// Create a new Tide server with shared global state.
/// Create a new Tide server with shared application scoped state.
///
/// Global state is useful for storing items
/// Application scoped state is useful for storing items
///
/// # Examples
///
Expand Down Expand Up @@ -259,14 +259,13 @@ impl<State: Send + Sync + 'static> Server<State> {

/// Add middleware to an application.
///
/// Middleware provides application-global customization of the
/// request/response cycle, such as compression, logging, or header
/// modification. Middleware is invoked when processing a request, and can
/// either continue processing (possibly modifying the response) or
/// immediately return a response. See the [`Middleware`] trait for details.
/// Middleware provides customization of the request/response cycle, such as compression,
/// logging, or header modification. Middleware is invoked when processing a request, and can
/// either continue processing (possibly modifying the response) or immediately return a
/// response. See the [`Middleware`] trait for details.
///
/// Middleware can only be added at the "top level" of an application,
/// and is processed in the order in which it is applied.
/// Middleware can only be added at the "top level" of an application, and is processed in the
/// order in which it is applied.
pub fn middleware<M>(&mut self, middleware: M) -> &mut Self
where
M: Middleware<State> + Debug,
Expand Down

0 comments on commit fd2a545

Please sign in to comment.