Struct Shared

struct Shared<S> { ... }

A MakeService that produces services by cloning an inner service.

Example

# use std::task::{Context, Poll};
# use std::pin::Pin;
# use std::convert::Infallible;
use tower::make::{MakeService, Shared};
use tower::buffer::Buffer;
use tower::Service;
use futures::future::{Ready, ready};

// An example connection type
struct Connection {}

// An example request type
struct Request {}

// An example response type
struct Response {}

// Some service that doesn't implement `Clone`
struct MyService;

impl Service<Request> for MyService {
    type Response = Response;
    type Error = Infallible;
    type Future = Ready<Result<Response, Infallible>>;

    fn poll_ready(&mut self, _cx: &mut Context<'_>) -> Poll<Result<(), Self::Error>> {
        Poll::Ready(Ok(()))
    }

    fn call(&mut self, req: Request) -> Self::Future {
        ready(Ok(Response {}))
    }
}

// Example function that runs a service by accepting new connections and using
// `Make` to create new services that might be bound to the connection.
//
// This is similar to what you might find in hyper.
async fn serve_make_service<Make>(make: Make)
where
    Make: MakeService<Connection, Request>
{
    // ...
}

# async {
// Our service
let svc = MyService;

// Make it `Clone` by putting a channel in front
let buffered = Buffer::new(svc, 1024);

// Convert it into a `MakeService`
let make = Shared::new(buffered);

// Run the service and just ignore the `Connection`s as `MyService` doesn't need them
serve_make_service(make).await;
# };

Implementations

impl<S> Shared<S>

const fn new(service: S) -> Self

Create a new Shared from a service.

impl<M, S, Target, Request> MakeService for Shared<S>

fn poll_ready(self: &mut Self, cx: &mut Context<'_>) -> Poll<Result<(), <M as MakeService<Target, Request>>::MakeError>>
fn make_service(self: &mut Self, target: Target) -> <M as MakeService<Target, Request>>::Future

impl<S> Freeze for Shared<S>

impl<S> RefUnwindSafe for Shared<S>

impl<S> Send for Shared<S>

impl<S> Sync for Shared<S>

impl<S> Unpin for Shared<S>

impl<S> UnsafeUnpin for Shared<S>

impl<S> UnwindSafe for Shared<S>

impl<S, T> Service for Shared<S>

fn poll_ready(self: &mut Self, _cx: &mut Context<'_>) -> Poll<Result<(), <Self as >::Error>>
fn call(self: &mut Self, _target: T) -> <Self as >::Future

impl<S: $crate::clone::Clone> Clone for Shared<S>

fn clone(self: &Self) -> Shared<S>

impl<S: $crate::fmt::Debug> Debug for Shared<S>

fn fmt(self: &Self, f: &mut Formatter<'_>) -> Result

impl<S: $crate::marker::Copy> Copy for Shared<S>

impl<T> Any for Shared<S>

fn type_id(self: &Self) -> TypeId

impl<T> Borrow for Shared<S>

fn borrow(self: &Self) -> &T

impl<T> BorrowMut for Shared<S>

fn borrow_mut(self: &mut Self) -> &mut T

impl<T> CloneToUninit for Shared<S>

unsafe fn clone_to_uninit(self: &Self, dest: *mut u8)

impl<T> From for Shared<S>

fn from(t: T) -> T

Returns the argument unchanged.

impl<T> Instrument for Shared<S>

impl<T> ToOwned for Shared<S>

fn to_owned(self: &Self) -> T
fn clone_into(self: &Self, target: &mut T)

impl<T> WithSubscriber for Shared<S>

impl<T, Request> ServiceExt for Shared<S>

impl<T, U> Into for Shared<S>

fn into(self: Self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of [From]<T> for U chooses to do.

impl<T, U> TryFrom for Shared<S>

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

impl<T, U> TryInto for Shared<S>

fn try_into(self: Self) -> Result<U, <U as TryFrom<T>>::Error>