This commit is contained in:
nora 2022-09-15 21:55:02 +02:00
parent 0f642ee243
commit 8779d291ec
4 changed files with 20 additions and 43 deletions

View file

@ -1,4 +1,4 @@
use crate::sealed::Sealed;
use crate::Sealed;
use futures_core::TryStream;
use std::{
pin::Pin,

View file

@ -1,18 +1,10 @@
// #![allow(warnings)]
#[macro_use]
pub(crate) mod macros;
pub mod balance;
pub mod discover;
pub mod make;
#[allow(unreachable_pub)]
mod sealed {
pub trait Sealed<T> {}
}
pub trait Sealed<T> {}
/// Alias for a type-erased error type.
pub type BoxError = Box<dyn std::error::Error + Send + Sync>;
@ -24,7 +16,6 @@ mod load {
}
}
use std::future::Future;
use std::task::{Context, Poll};

View file

@ -1,28 +0,0 @@
macro_rules! opaque_future {
($(#[$m:meta])* pub type $name:ident<$($param:ident),+> = $actual:ty;) => {
$(#[$m])*
pub struct $name<$($param),+> {
inner: $actual
}
impl<$($param),+> $name<$($param),+> {
pub(crate) fn new(inner: $actual) -> Self {
Self {
inner
}
}
}
impl<$($param),+> std::future::Future for $name<$($param),+>
where
$actual: std::future::Future,
{
type Output = <$actual as std::future::Future>::Output;
#[inline]
fn poll(self: std::pin::Pin<&mut Self>, cx: &mut std::task::Context<'_>) -> std::task::Poll<Self::Output> {
todo!()
}
}
}
}

View file

@ -1,6 +1,6 @@
//! Trait aliases for Services that produce specific types of Responses.
use crate::sealed::Sealed;
use crate::Sealed;
use crate::Service;
use std::task::{Context, Poll};
@ -27,9 +27,23 @@ where
}
}
opaque_future! {
/// Response future from [`Shared`] services.
pub type SharedFuture<S> = futures_util::future::Ready<Result<S, Infallible>>;
pub struct SharedFuture<S> {
_s: S,
}
impl<S> std::future::Future for SharedFuture<S>
where
futures_util::future::Ready<Result<S, Infallible>>: std::future::Future,
{
type Output =
<futures_util::future::Ready<Result<S, Infallible>> as std::future::Future>::Output;
fn poll(
self: std::pin::Pin<&mut Self>,
cx: &mut std::task::Context<'_>,
) -> std::task::Poll<Self::Output> {
todo!()
}
}
pub trait MakeService<Target, Request> {