mirror of
https://github.com/Noratrieb/101844-repro.git
synced 2026-01-14 14:25:02 +01:00
freestanding
This commit is contained in:
parent
3400568387
commit
0241ea2615
4 changed files with 111 additions and 152 deletions
40
Cargo.lock
generated
40
Cargo.lock
generated
|
|
@ -9,46 +9,6 @@ dependencies = [
|
||||||
"tower",
|
"tower",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "futures-core"
|
|
||||||
version = "0.3.24"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "4e5aa3de05362c3fb88de6531e6296e85cde7739cccad4b9dfeeb7f6ebce56bf"
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "futures-task"
|
|
||||||
version = "0.3.24"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "a6508c467c73851293f390476d4491cf4d227dbabcd4170f3bb6044959b294f1"
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "futures-util"
|
|
||||||
version = "0.3.24"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "44fb6cb1be61cc1d2e43b262516aafcf63b241cffdb1d3fa115f91d9c7b09c90"
|
|
||||||
dependencies = [
|
|
||||||
"futures-core",
|
|
||||||
"futures-task",
|
|
||||||
"pin-project-lite",
|
|
||||||
"pin-utils",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "pin-project-lite"
|
|
||||||
version = "0.2.9"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "e0a7ae3ac2f1173085d398531c705756c94a4c56843785df85a60c1a0afac116"
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "pin-utils"
|
|
||||||
version = "0.1.0"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184"
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "tower"
|
name = "tower"
|
||||||
version = "0.4.13"
|
version = "0.4.13"
|
||||||
dependencies = [
|
|
||||||
"futures-core",
|
|
||||||
"futures-util",
|
|
||||||
]
|
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,3 @@ edition = "2018"
|
||||||
|
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
futures-core = { version = "0.3" }
|
|
||||||
futures-util = { version = "0.3", default-features = false, features = [
|
|
||||||
"alloc",
|
|
||||||
] }
|
|
||||||
|
|
|
||||||
|
|
@ -1,104 +0,0 @@
|
||||||
use crate::MakeService;
|
|
||||||
use crate::Service;
|
|
||||||
use crate::{Discover};
|
|
||||||
use futures_core::Stream;
|
|
||||||
use futures_util::future::{self};
|
|
||||||
use std::hash::Hash;
|
|
||||||
use std::marker::PhantomData;
|
|
||||||
use std::{
|
|
||||||
pin::Pin,
|
|
||||||
task::{Context, Poll},
|
|
||||||
};
|
|
||||||
|
|
||||||
pub struct Balance<D, Req> {
|
|
||||||
_req: PhantomData<(D, Req)>,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<D, Req> Balance<D, Req>
|
|
||||||
where
|
|
||||||
D: Discover,
|
|
||||||
D::Service: Service<Req>,
|
|
||||||
<D::Service as Service<Req>>::Error: Into<crate::BoxError>,
|
|
||||||
{
|
|
||||||
pub fn new(_: D) -> Self {
|
|
||||||
todo!()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<D, Req> Service<Req> for Balance<D, Req>
|
|
||||||
where
|
|
||||||
D: Discover + Unpin,
|
|
||||||
D::Key: Hash + Clone,
|
|
||||||
D::Error: Into<crate::BoxError>,
|
|
||||||
D::Service: Service<Req>,
|
|
||||||
<D::Service as Service<Req>>::Error: Into<crate::BoxError>,
|
|
||||||
{
|
|
||||||
type Response = <D::Service as Service<Req>>::Response;
|
|
||||||
type Error = crate::BoxError;
|
|
||||||
type Future = future::MapErr<
|
|
||||||
<D::Service as Service<Req>>::Future,
|
|
||||||
fn(<D::Service as Service<Req>>::Error) -> crate::BoxError,
|
|
||||||
>;
|
|
||||||
}
|
|
||||||
|
|
||||||
pub struct PoolDiscoverer<MS, Target, Request>
|
|
||||||
where
|
|
||||||
MS: MakeService<Target, Request>,
|
|
||||||
{
|
|
||||||
_p: PhantomData<(MS, Target, Request)>,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<MS, Target, Request> Stream for PoolDiscoverer<MS, Target, Request>
|
|
||||||
where
|
|
||||||
MS: MakeService<Target, Request>,
|
|
||||||
{
|
|
||||||
type Item = Result<(usize, DropNotifyService<MS::Service>), MS::Error>;
|
|
||||||
|
|
||||||
fn poll_next(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Option<Self::Item>> {
|
|
||||||
todo!()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub struct Builder {}
|
|
||||||
|
|
||||||
impl Builder {
|
|
||||||
pub fn build<MS, Target, Request>() -> ()
|
|
||||||
where
|
|
||||||
MS: MakeService<Target, Request>,
|
|
||||||
MS::Error: Into<crate::BoxError>,
|
|
||||||
{
|
|
||||||
let d: PoolDiscoverer<MS, Target, Request> = todo!();
|
|
||||||
|
|
||||||
// THE CRITICAL STATEMENT
|
|
||||||
let x = Balance::new(Box::pin(d));
|
|
||||||
|
|
||||||
todo!()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub struct Pool<MS, Target, Request> {
|
|
||||||
balance: (MS, Target, Request),
|
|
||||||
}
|
|
||||||
|
|
||||||
type PinBalance<S, Request> = Balance<Pin<Box<S>>, Request>;
|
|
||||||
|
|
||||||
impl<MS, Target, Req> Service<Req> for Pool<MS, Target, Req>
|
|
||||||
where
|
|
||||||
MS: MakeService<Target, Req>,
|
|
||||||
MS::Error: Into<crate::BoxError>,
|
|
||||||
Target: Clone,
|
|
||||||
{
|
|
||||||
type Response = <PinBalance<PoolDiscoverer<MS, Target, Req>, Req> as Service<Req>>::Response;
|
|
||||||
type Error = <PinBalance<PoolDiscoverer<MS, Target, Req>, Req> as Service<Req>>::Error;
|
|
||||||
type Future = <PinBalance<PoolDiscoverer<MS, Target, Req>, Req> as Service<Req>>::Future;
|
|
||||||
}
|
|
||||||
|
|
||||||
pub struct DropNotifyService<Svc> {
|
|
||||||
svc: Svc,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<Request, Svc: Service<Request>> Service<Request> for DropNotifyService<Svc> {
|
|
||||||
type Response = Svc::Response;
|
|
||||||
type Future = Svc::Future;
|
|
||||||
type Error = Svc::Error;
|
|
||||||
}
|
|
||||||
115
tower/src/lib.rs
115
tower/src/lib.rs
|
|
@ -1,6 +1,39 @@
|
||||||
pub mod balance;
|
use std::marker::PhantomData;
|
||||||
|
use std::{
|
||||||
|
pin::Pin,
|
||||||
|
task::{Context, Poll},
|
||||||
|
};
|
||||||
|
|
||||||
use futures_core::TryStream;
|
use core::ops::DerefMut;
|
||||||
|
|
||||||
|
pub trait Stream {
|
||||||
|
type Item;
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<S: ?Sized + Stream + Unpin> Stream for &mut S {
|
||||||
|
type Item = S::Item;
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<P> Stream for Pin<P>
|
||||||
|
where
|
||||||
|
P: DerefMut + Unpin,
|
||||||
|
P::Target: Stream,
|
||||||
|
{
|
||||||
|
type Item = <P::Target as Stream>::Item;
|
||||||
|
}
|
||||||
|
|
||||||
|
pub trait TryStream: Stream {
|
||||||
|
type Ok;
|
||||||
|
type Error;
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<S, T, E> TryStream for S
|
||||||
|
where
|
||||||
|
S: ?Sized + Stream<Item = Result<T, E>>,
|
||||||
|
{
|
||||||
|
type Ok = T;
|
||||||
|
type Error = E;
|
||||||
|
}
|
||||||
|
|
||||||
pub type BoxError = Box<dyn std::error::Error + Send + Sync>;
|
pub type BoxError = Box<dyn std::error::Error + Send + Sync>;
|
||||||
|
|
||||||
|
|
@ -21,7 +54,6 @@ where
|
||||||
}
|
}
|
||||||
|
|
||||||
pub trait Service<Request> {
|
pub trait Service<Request> {
|
||||||
type Response;
|
|
||||||
type Error;
|
type Error;
|
||||||
type Future;
|
type Future;
|
||||||
}
|
}
|
||||||
|
|
@ -29,7 +61,82 @@ pub trait Service<Request> {
|
||||||
pub trait MakeService<Target, Request> {
|
pub trait MakeService<Target, Request> {
|
||||||
type Response;
|
type Response;
|
||||||
type Error;
|
type Error;
|
||||||
type Service: Service<Request, Response = Self::Response, Error = Self::Error>;
|
type Service: Service<Request, Error = Self::Error>;
|
||||||
type Future;
|
type Future;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub struct Balance<D, Req> {
|
||||||
|
_req: PhantomData<(D, Req)>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<D, Req> Balance<D, Req>
|
||||||
|
where
|
||||||
|
D: Discover,
|
||||||
|
D::Service: Service<Req>,
|
||||||
|
<D::Service as Service<Req>>::Error: Into<crate::BoxError>,
|
||||||
|
{
|
||||||
|
pub fn new(_: D) -> Self {
|
||||||
|
todo!()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<D, Req> Service<Req> for Balance<D, Req> {
|
||||||
|
type Error = crate::BoxError;
|
||||||
|
type Future = std::future::Ready<()>;
|
||||||
|
}
|
||||||
|
|
||||||
|
pub struct PoolDiscoverer<MS, Target, Request>
|
||||||
|
where
|
||||||
|
MS: MakeService<Target, Request>,
|
||||||
|
{
|
||||||
|
_p: PhantomData<(MS, Target, Request)>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<MS, Target, Request> Stream for PoolDiscoverer<MS, Target, Request>
|
||||||
|
where
|
||||||
|
MS: MakeService<Target, Request>,
|
||||||
|
{
|
||||||
|
type Item = Result<(usize, DropNotifyService<MS::Service>), MS::Error>;
|
||||||
|
}
|
||||||
|
|
||||||
|
pub struct Builder {}
|
||||||
|
|
||||||
|
impl Builder {
|
||||||
|
pub fn build<MS, Target, Request>() -> ()
|
||||||
|
where
|
||||||
|
MS: MakeService<Target, Request>,
|
||||||
|
MS::Error: Into<crate::BoxError>,
|
||||||
|
{
|
||||||
|
let d: PoolDiscoverer<MS, Target, Request> = todo!();
|
||||||
|
|
||||||
|
// THE CRITICAL STATEMENT
|
||||||
|
let x = Balance::new(Box::pin(d));
|
||||||
|
|
||||||
|
todo!()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub struct Pool<MS, Target, Request> {
|
||||||
|
balance: (MS, Target, Request),
|
||||||
|
}
|
||||||
|
|
||||||
|
type PinBalance<S, Request> = Balance<Pin<Box<S>>, Request>;
|
||||||
|
|
||||||
|
impl<MS, Target, Req> Service<Req> for Pool<MS, Target, Req>
|
||||||
|
where
|
||||||
|
MS: MakeService<Target, Req>,
|
||||||
|
MS::Error: Into<crate::BoxError>,
|
||||||
|
Target: Clone,
|
||||||
|
{
|
||||||
|
type Error = <PinBalance<PoolDiscoverer<MS, Target, Req>, Req> as Service<Req>>::Error;
|
||||||
|
type Future = <PinBalance<PoolDiscoverer<MS, Target, Req>, Req> as Service<Req>>::Future;
|
||||||
|
}
|
||||||
|
|
||||||
|
pub struct DropNotifyService<Svc> {
|
||||||
|
svc: Svc,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<Request, Svc: Service<Request>> Service<Request> for DropNotifyService<Svc> {
|
||||||
|
type Future = Svc::Future;
|
||||||
|
type Error = Svc::Error;
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue