pretty small huh

This commit is contained in:
nora 2022-09-15 22:57:57 +02:00
parent d4e9233099
commit 236cac18c2

View file

@ -3,7 +3,7 @@ use std::pin::Pin;
use core::ops::DerefMut; use core::ops::DerefMut;
pub trait Stream { trait Stream {
type Item; type Item;
} }
@ -15,7 +15,7 @@ where
type Item = <P::Target as Stream>::Item; type Item = <P::Target as Stream>::Item;
} }
pub trait TryStream: Stream { trait TryStream: Stream {
type Ok; type Ok;
} }
@ -26,9 +26,7 @@ where
type Ok = T; type Ok = T;
} }
pub type BoxError = (); trait Discover {
pub trait Discover {
type Service; type Service;
} }
@ -42,17 +40,14 @@ where
pub trait Service<Request> { pub trait Service<Request> {
type Error; type Error;
type Future;
} }
pub trait MakeService { pub trait MakeService {
type Response;
type Error; type Error;
type Service: Service<(), Error = Self::Error>; type Service: Service<(), Error = Self::Error>;
type Future;
} }
pub struct Balance<D, Req> { struct Balance<D, Req> {
_req: PhantomData<(D, Req)>, _req: PhantomData<(D, Req)>,
} }
@ -60,65 +55,48 @@ impl<D, Req> Balance<D, Req>
where where
D: Discover, D: Discover,
D::Service: Service<Req>, D::Service: Service<Req>,
<D::Service as Service<Req>>::Error: Into<crate::BoxError>, <D::Service as Service<Req>>::Error: Into<()>,
{ {
pub fn new(_: D) -> Self { fn new(_: D) -> Self {
todo!() todo!()
} }
} }
impl<D, Req> Service<Req> for Balance<D, Req> { impl<D, Req> Service<Req> for Balance<D, Req> {
type Error = crate::BoxError; type Error = ();
type Future = std::future::Ready<()>;
} }
pub struct PoolDiscoverer<MS, Request> struct PoolDiscoverer<MS>
where where
MS: MakeService, MS: MakeService,
{ {
_p: PhantomData<(MS, Request)>, _x: MS,
} }
impl<MS, Request> Stream for PoolDiscoverer<MS, Request> impl<MS> Stream for PoolDiscoverer<MS>
where where
MS: MakeService, MS: MakeService,
{ {
type Item = (usize, SvcWrap<MS::Service>); type Item = (usize, SvcWrap<MS::Service>);
} }
pub struct Builder {} pub struct Builder;
impl Builder { impl Builder {
pub fn build<MS, Request>() pub fn build<MS, Request>()
where where
MS: MakeService, MS: MakeService,
MS::Error: Into<crate::BoxError>, MS::Error: Into<()>,
{ {
let d: PoolDiscoverer<MS, Request> = todo!(); let d: PoolDiscoverer<MS> = todo!();
// THE CRITICAL STATEMENT // THE CRITICAL STATEMENT
let _ = Balance::new(Box::pin(d)); let _ = Balance::new(Box::pin(d));
} }
} }
pub struct Pool<MS, Request> { struct SvcWrap<Svc>(Svc);
balance: (MS, Request),
}
impl<MS, Req> Service<Req> for Pool<MS, Req>
where
MS: MakeService,
MS::Error: Into<crate::BoxError>,
{
type Error = <Balance<PoolDiscoverer<MS, Req>, Req> as Service<Req>>::Error;
type Future = <Balance<PoolDiscoverer<MS, Req>, Req> as Service<Req>>::Future;
}
pub struct SvcWrap<Svc> {
svc: Svc,
}
impl<Request, Svc: Service<Request>> Service<Request> for SvcWrap<Svc> { impl<Request, Svc: Service<Request>> Service<Request> for SvcWrap<Svc> {
type Future = Svc::Future;
type Error = Svc::Error; type Error = Svc::Error;
} }