Struct Singleton

pub struct Singleton<M, Dst>
where
    M: Service<Dst>, { /* private fields */ }

A singleton pool over an inner service.

The singleton wraps an inner service maker, bundling all calls to ensure only one service is created. Once made, it returns clones of the made service.

Implementations

impl<M, Target> Singleton<M, Target> where M: Service<Target>, M::Response: Clone,

fn new(mk_svc: M) -> Self

Create a new singleton pool over an inner make service.

fn retain<F>(&mut self, predicate: F)
where
    F: FnMut(&mut M::Response) -> bool,

Retains the inner made service if specified by the predicate.

fn is_empty(&self) -> bool

Returns whether this singleton pool is empty.

If this pool has created a shared instance, or is currently in the process of creating one, this returns false.

Trait Implementations

impl<M, Dst: Debug> Debug for Singleton<M, Dst> where M: Service<Dst> + Debug, M::Future: Debug, M::Response: Debug,

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

impl<M, Target> Clone for Singleton<M, Target> where M: Service<Target> + Clone,

fn clone(&self) -> Self

impl<M, Target> Service<Target> for Singleton<M, Target> where M: Service<Target>, M::Response: Clone, M::Error: Into<Box<dyn Error + Send + Sync>>,

type Response = Singled<<M as Service<Target>>::Future, <M as Service<Target>>::Response>;
type Error = SingletonError;
type Future = SingletonFuture<<M as Service<Target>>::Future, <M as Service<Target>>::Response>;
fn poll_ready(&mut self, cx: &mut Context<'_>) -> Poll<Result<(), Self::Error>>
fn call(&mut self, dst: Target) -> Self::Future

Auto Trait Implementations

impl<M, Dst> Freeze for Singleton<M, Dst> where M: Freeze, Arc<Mutex<State<<M as Service<Dst>>::Future, <M as Service<Dst>>::Response>>>: Freeze,

impl<M, Dst> RefUnwindSafe for Singleton<M, Dst> where M: RefUnwindSafe, Arc<Mutex<State<<M as Service<Dst>>::Future, <M as Service<Dst>>::Response>>>: RefUnwindSafe,

impl<M, Dst> Send for Singleton<M, Dst> where M: Send, Arc<Mutex<State<<M as Service<Dst>>::Future, <M as Service<Dst>>::Response>>>: Send,

impl<M, Dst> Sync for Singleton<M, Dst> where M: Sync, Arc<Mutex<State<<M as Service<Dst>>::Future, <M as Service<Dst>>::Response>>>: Sync,

impl<M, Dst> Unpin for Singleton<M, Dst> where M: Unpin, Arc<Mutex<State<<M as Service<Dst>>::Future, <M as Service<Dst>>::Response>>>: Unpin,

impl<M, Dst> UnsafeUnpin for Singleton<M, Dst> where M: UnsafeUnpin, Arc<Mutex<State<<M as Service<Dst>>::Future, <M as Service<Dst>>::Response>>>: UnsafeUnpin,

impl<M, Dst> UnwindSafe for Singleton<M, Dst> where M: UnwindSafe, Arc<Mutex<State<<M as Service<Dst>>::Future, <M as Service<Dst>>::Response>>>: UnwindSafe,

Blanket Implementations

impl<T> Any for Singleton<M, Dst> where T: 'static + ?Sized,

fn type_id(&self) -> TypeId

impl<T> Borrow<T> for Singleton<M, Dst> where T: ?Sized,

fn borrow(&self) -> &T

impl<T> BorrowMut<T> for Singleton<M, Dst> where T: ?Sized,

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

impl<T> CloneToUninit for Singleton<M, Dst> where T: Clone,

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

impl<T> From<T> for Singleton<M, Dst>

fn from(t: T) -> T

Returns the argument unchanged.

impl<T> Instrument for Singleton<M, Dst>

impl<T> ToOwned for Singleton<M, Dst> where T: Clone,

type Owned = T;
fn to_owned(&self) -> T
fn clone_into(&self, target: &mut T)

impl<T> WithSubscriber for Singleton<M, Dst>

impl<T, U> Into<U> for Singleton<M, Dst> where U: From<T>,

fn into(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<U> for Singleton<M, Dst> where U: Into<T>,

type Error = never;
fn try_from(value: U) -> Result<T, never>

impl<T, U> TryInto<U> for Singleton<M, Dst> where U: TryFrom<T>,

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