use hyper::{Request, Response};
use tower::{Service, MakeService};
use super::connect::Connect;
use super::pool;
pub struct Client<M> {
make_svc: M,
}
type PoolKey = hyper::Uri;
struct ConnectingPool<C, P> {
connector: C,
pool: P,
}
struct PoolableSvc<S>(S);
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
#[allow(dead_code)]
pub enum Ver {
Auto,
Http2,
}
impl<M, E> Client<M>
where
M: MakeService<
hyper::Uri,
Request<()>,
Response = Response<()>,
Error = E,
MakeError = E,
>,
{
pub async fn request(&mut self, req: Request<()>) -> Result<Response<()>, E> {
let mut svc = self.make_svc.make_service(req.uri().clone()).await?;
svc.call(req).await
}
}
impl<M, E> Client<M>
where
M: MakeService<
hyper::Uri,
Request<()>,
Response = Response<()>,
Error = E,
MakeError = E,
>,
{
}
impl<C, P> ConnectingPool<C, P>
where
C: Connect,
C::_Svc: Unpin + Send + 'static,
{
async fn connection_for(&self, target: PoolKey) -> Result<pool::Pooled<PoolableSvc<C::_Svc>, PoolKey>, ()> {
todo!()
}
}
impl<S> pool::Poolable for PoolableSvc<S>
where
S: Unpin + Send + 'static,
{
fn is_open(&self) -> bool {
true
}
fn reserve(self) -> pool::Reservation<Self> {
pool::Reservation::Unique(self)
}
fn can_share(&self) -> bool {
false
}
}