Skip to content

Commit

Permalink
docs(tower): moved docs from private tower::util::boxed module (tow…
Browse files Browse the repository at this point in the history
…er-rs#684)

Now they're on the public `BoxService` struct that referenced them.

Fixes tower-rs#683.
  • Loading branch information
dcormier authored Sep 13, 2022
1 parent 4362dfc commit c5632a2
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 35 deletions.
34 changes: 0 additions & 34 deletions tower/src/util/boxed/mod.rs
Original file line number Diff line number Diff line change
@@ -1,37 +1,3 @@
//! Trait object [`Service`] instances
//!
//! Dynamically dispatched [`Service`] objects allow for erasing the underlying
//! [`Service`] type and using the `Service` instances as opaque handles. This can
//! be useful when the service instance cannot be explicitly named for whatever
//! reason.
//!
//! There are two variants of service objects. [`BoxService`] requires both the
//! service and the response future to be [`Send`]. These values can move freely
//! across threads. [`UnsyncBoxService`] requires both the service and the
//! response future to remain on the current thread. This is useful for
//! representing services that are backed by [`Rc`] or other non-[`Send`] types.
//!
//! # Examples
//!
//! ```
//! use futures_util::future::ready;
//! # use tower_service::Service;
//! # use tower::util::{BoxService, service_fn};
//! // Respond to requests using a closure, but closures cannot be named...
//! # pub fn main() {
//! let svc = service_fn(|mut request: String| {
//! request.push_str(" response");
//! ready(Ok(request))
//! });
//!
//! let service: BoxService<String, String, ()> = BoxService::new(svc);
//! # drop(service);
//! }
//! ```
//!
//! [`Service`]: crate::Service
//! [`Rc`]: std::rc::Rc

mod layer;
mod sync;
mod unsync;
Expand Down
26 changes: 25 additions & 1 deletion tower/src/util/boxed/sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,31 @@ use std::{
/// If you need a boxed [`Service`] that implements [`Clone`] consider using
/// [`BoxCloneService`](crate::util::BoxCloneService).
///
/// See module level documentation for more details.
/// Dynamically dispatched [`Service`] objects allow for erasing the underlying
/// [`Service`] type and using the `Service` instances as opaque handles. This can
/// be useful when the service instance cannot be explicitly named for whatever
/// reason.
///
/// # Examples
///
/// ```
/// use futures_util::future::ready;
/// # use tower_service::Service;
/// # use tower::util::{BoxService, service_fn};
/// // Respond to requests using a closure, but closures cannot be named...
/// # pub fn main() {
/// let svc = service_fn(|mut request: String| {
/// request.push_str(" response");
/// ready(Ok(request))
/// });
///
/// let service: BoxService<String, String, ()> = BoxService::new(svc);
/// # drop(service);
/// }
/// ```
///
/// [`Service`]: crate::Service
/// [`Rc`]: std::rc::Rc
pub struct BoxService<T, U, E> {
inner: Box<dyn Service<T, Response = U, Error = E, Future = BoxFuture<U, E>> + Send>,
}
Expand Down

0 comments on commit c5632a2

Please sign in to comment.