Struct BoxService

Source
pub struct BoxService<Req, Res, Err> { /* private fields */ }
Expand description

装箱的 Service 特征对象。

BoxService 将服务转换为特征对象并装箱,允许服务的 Future 是动态的。

如果需要一个实现 Clone 的装箱服务,考虑使用 BoxCloneServiceArcService

Implementations§

Source§

impl<Req, Res, Err> BoxService<Req, Res, Err>

Source

pub fn new<S>(service: S) -> Self
where S: Service<Req, Response = Res, Error = Err> + 'static,

将服务转换为Service特征对象并装箱。

Trait Implementations§

Source§

impl<Req, Res, Err> Debug for BoxService<Req, Res, Err>

Source§

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

Formats the value using the given formatter. Read more
Source§

impl<Req, Res, Err> Service<Req> for BoxService<Req, Res, Err>

Source§

type Response = Res

服务返回的响应。
Source§

type Error = Err

服务产生的错误。
Source§

fn call( &self, req: Req, ) -> impl Future<Output = Result<Self::Response, Self::Error>> + Send

处理请求并异步返回响应。

Auto Trait Implementations§

§

impl<Req, Res, Err> Freeze for BoxService<Req, Res, Err>

§

impl<Req, Res, Err> !RefUnwindSafe for BoxService<Req, Res, Err>

§

impl<Req, Res, Err> Send for BoxService<Req, Res, Err>

§

impl<Req, Res, Err> Sync for BoxService<Req, Res, Err>

§

impl<Req, Res, Err> Unpin for BoxService<Req, Res, Err>

§

impl<Req, Res, Err> !UnwindSafe for BoxService<Req, Res, Err>

Blanket Implementations§

Source§

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

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

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

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

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

Source§

impl<S, Req> ServiceExt<Req> for S
where S: Service<Req> + ?Sized,

Source§

fn with<T, R>(self, middleware: T) -> T::Service
where Self: Sized, T: Middleware<Self>, T::Service: Service<R>,

在此服务上应用中间件。 Read more
Source§

fn then<F, Fut, Res, Err>(self, f: F) -> Then<Self, F>
where Self: Sized, F: Fn(Result<Self::Response, Self::Error>) -> Fut + Send + Sync, Fut: Future<Output = Result<Res, Err>> + Send,

在此服务执行完成后执行给定的异步函数。 Read more
Source§

fn and_then<F, Fut, Res>(self, f: F) -> AndThen<Self, F>
where Self: Sized, F: Fn(Self::Response) -> Fut + Send + Sync, Fut: Future<Output = Result<Res, Self::Error>> + Send,

在此服务执行成功后执行给定的异步函数。 Read more
Source§

fn or_else<F, Fut, Err>(self, f: F) -> OrElse<Self, F>
where Self: Sized, F: Fn(Self::Error) -> Fut + Send + Sync, Fut: Future<Output = Result<Self::Response, Err>> + Send,

在此服务执行失败后执行给定的异步函数。 Read more
Source§

fn map_result<F, Res, Err>(self, f: F) -> MapResult<Self, F>
where Self: Sized, F: Fn(Result<Self::Response, Self::Error>) -> Result<Res, Err> + Send + Sync,

将此服务返回的结果映射为其他值。 Read more
Source§

fn map_response<F, Res>(self, f: F) -> MapResponse<Self, F>
where Self: Sized, F: Fn(Self::Response) -> Res + Send + Sync,

将此服务返回的响应映射为其他值。 Read more
Source§

fn map_err<F, Err>(self, f: F) -> MapErr<Self, F>
where Self: Sized, F: Fn(Self::Error) -> Err + Send + Sync,

将此服务返回的错误映射为其他值。 Read more
Source§

fn map_request<F, R>(self, f: F) -> MapRequest<Self, F>
where Self: Sized, F: Fn(R) -> Req + Send + Sync,

将发送给此服务的请求映射为其他值。 Read more
Source§

fn boxed(self) -> BoxService<Req, Self::Response, Self::Error>
where Self: Sized + 'static,

将此服务转换为 Service 特征对象并装箱。 Read more
Source§

fn boxed_clone(self) -> BoxCloneService<Req, Self::Response, Self::Error>
where Self: Sized + Clone + 'static,

将此服务转换为 Service 特征对象并装箱。 Read more
Source§

fn boxed_arc(self) -> ArcService<Req, Self::Response, Self::Error>
where Self: Sized + 'static,

将此服务转换为 Service 特征对象并装箱。 Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

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

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

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

Performs the conversion.