mirror of
https://github.com/Noratrieb/101844-repro.git
synced 2026-01-14 14:25:02 +01:00
move
This commit is contained in:
parent
694ce70ce3
commit
93c5022ae4
3 changed files with 60 additions and 68 deletions
|
|
@ -1,5 +1,5 @@
|
|||
use crate::load::Load;
|
||||
use crate::make::MakeService;
|
||||
use crate::MakeService;
|
||||
use crate::Service;
|
||||
use crate::{Change, Discover};
|
||||
use futures_core::Stream;
|
||||
|
|
|
|||
|
|
@ -1,10 +1,9 @@
|
|||
// #![allow(warnings)]
|
||||
|
||||
pub mod balance;
|
||||
pub mod make;
|
||||
|
||||
use std::future::Future;
|
||||
use futures_core::TryStream;
|
||||
use std::{convert::Infallible, future::Future};
|
||||
pub trait Sealed<T> {}
|
||||
|
||||
/// Alias for a type-erased error type.
|
||||
|
|
@ -52,3 +51,61 @@ pub trait Service<Request> {
|
|||
/// The future response value.
|
||||
type Future: Future<Output = Result<Self::Response, Self::Error>>;
|
||||
}
|
||||
|
||||
pub struct Shared<S> {
|
||||
service: S,
|
||||
}
|
||||
|
||||
impl<S, T> Service<T> for Shared<S>
|
||||
where
|
||||
S: Clone,
|
||||
{
|
||||
type Response = S;
|
||||
type Error = Infallible;
|
||||
type Future = SharedFuture<S>;
|
||||
}
|
||||
|
||||
pub struct SharedFuture<S> {
|
||||
_s: S,
|
||||
}
|
||||
|
||||
impl<S> std::future::Future for SharedFuture<S>
|
||||
where
|
||||
std::future::Ready<Result<S, Infallible>>: std::future::Future,
|
||||
{
|
||||
type Output = <std::future::Ready<Result<S, Infallible>> as std::future::Future>::Output;
|
||||
|
||||
fn poll(
|
||||
self: std::pin::Pin<&mut Self>,
|
||||
_: &mut std::task::Context<'_>,
|
||||
) -> std::task::Poll<Self::Output> {
|
||||
todo!()
|
||||
}
|
||||
}
|
||||
|
||||
pub trait MakeService<Target, Request> {
|
||||
type Response;
|
||||
type Error;
|
||||
type Service: Service<Request, Response = Self::Response, Error = Self::Error>;
|
||||
type MakeError;
|
||||
type Future;
|
||||
}
|
||||
|
||||
impl<M, S, Target, Request> Sealed<(Target, Request)> for M
|
||||
where
|
||||
M: Service<Target, Response = S>,
|
||||
S: Service<Request>,
|
||||
{
|
||||
}
|
||||
|
||||
impl<M, S, Target, Request> MakeService<Target, Request> for M
|
||||
where
|
||||
M: Service<Target, Response = S>,
|
||||
S: Service<Request>,
|
||||
{
|
||||
type Response = S::Response;
|
||||
type Error = S::Error;
|
||||
type Service = S;
|
||||
type MakeError = M::Error;
|
||||
type Future = M::Future;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,65 +0,0 @@
|
|||
//! Trait aliases for Services that produce specific types of Responses.
|
||||
|
||||
use crate::Sealed;
|
||||
use crate::Service;
|
||||
|
||||
use std::convert::Infallible;
|
||||
|
||||
pub struct Shared<S> {
|
||||
service: S,
|
||||
}
|
||||
|
||||
impl<S, T> Service<T> for Shared<S>
|
||||
where
|
||||
S: Clone,
|
||||
{
|
||||
type Response = S;
|
||||
type Error = Infallible;
|
||||
type Future = SharedFuture<S>;
|
||||
}
|
||||
|
||||
pub struct SharedFuture<S> {
|
||||
_s: S,
|
||||
}
|
||||
|
||||
impl<S> std::future::Future for SharedFuture<S>
|
||||
where
|
||||
std::future::Ready<Result<S, Infallible>>: std::future::Future,
|
||||
{
|
||||
type Output =
|
||||
<std::future::Ready<Result<S, Infallible>> as std::future::Future>::Output;
|
||||
|
||||
fn poll(
|
||||
self: std::pin::Pin<&mut Self>,
|
||||
_: &mut std::task::Context<'_>,
|
||||
) -> std::task::Poll<Self::Output> {
|
||||
todo!()
|
||||
}
|
||||
}
|
||||
|
||||
pub trait MakeService<Target, Request> {
|
||||
type Response;
|
||||
type Error;
|
||||
type Service: Service<Request, Response = Self::Response, Error = Self::Error>;
|
||||
type MakeError;
|
||||
type Future;
|
||||
}
|
||||
|
||||
impl<M, S, Target, Request> Sealed<(Target, Request)> for M
|
||||
where
|
||||
M: Service<Target, Response = S>,
|
||||
S: Service<Request>,
|
||||
{
|
||||
}
|
||||
|
||||
impl<M, S, Target, Request> MakeService<Target, Request> for M
|
||||
where
|
||||
M: Service<Target, Response = S>,
|
||||
S: Service<Request>,
|
||||
{
|
||||
type Response = S::Response;
|
||||
type Error = S::Error;
|
||||
type Service = S;
|
||||
type MakeError = M::Error;
|
||||
type Future = M::Future;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue