use super::AsyncOperator;
use core::task::{Context, Poll};
use tower_service::Service;
#[derive(Debug, Clone, Copy)]
pub struct ServiceOp<S> {
inner: S,
}
impl<S> ServiceOp<S> {
fn new<I>(inner: S) -> Self
where
S: Service<I>,
{
Self { inner }
}
}
impl<S, I, O> AsyncOperator<I> for ServiceOp<S>
where
S: Service<I, Response = O>,
{
type Output = O;
type Error = S::Error;
type Future<'a> = S::Future where S: 'a;
fn poll_ready(&mut self, cx: &mut Context<'_>) -> Poll<Result<(), Self::Error>> {
self.inner.poll_ready(cx)
}
fn next(&mut self, input: I) -> Self::Future<'_> {
self.inner.call(input)
}
}
pub trait ServiceOperator<I>: Service<I> {
fn into_async_operator(self) -> ServiceOp<Self>
where
Self: Sized,
{
ServiceOp::new(self)
}
}
impl<T, I> ServiceOperator<I> for T where T: Service<I> {}