|
| 1 | +// edition:2021 |
| 2 | + |
| 3 | +mod hyper { |
| 4 | + use std::{fmt::Debug, future::Future, marker::PhantomData, pin::Pin, task::Poll}; |
| 5 | + |
| 6 | + pub trait HttpBody { |
| 7 | + type Error; |
| 8 | + } |
| 9 | + impl HttpBody for () { |
| 10 | + //~^ ERROR not all trait items implemented, missing: `Error` |
| 11 | + // don't implement `Error` here for the ICE |
| 12 | + } |
| 13 | + |
| 14 | + pub struct Server<I, S>(I, S); |
| 15 | + |
| 16 | + pub fn serve<I, S>(_: S) -> Server<I, S> { |
| 17 | + todo!() |
| 18 | + } |
| 19 | + |
| 20 | + impl<S, B> Future for Server<(), S> |
| 21 | + where |
| 22 | + S: MakeServiceRef<(), (), ResBody = B>, |
| 23 | + B: HttpBody, |
| 24 | + B::Error: Debug, |
| 25 | + { |
| 26 | + type Output = (); |
| 27 | + |
| 28 | + fn poll(self: Pin<&mut Self>, _: &mut std::task::Context<'_>) -> Poll<Self::Output> { |
| 29 | + todo!() |
| 30 | + } |
| 31 | + } |
| 32 | + |
| 33 | + pub trait MakeServiceRef<Target, ReqBody> { |
| 34 | + type ResBody; |
| 35 | + } |
| 36 | + |
| 37 | + impl<T, S> MakeServiceRef<(), ()> for T |
| 38 | + where |
| 39 | + T: for<'a> Service<&'a (), Response = S>, |
| 40 | + S: Service<()>, |
| 41 | + { |
| 42 | + type ResBody = (); |
| 43 | + } |
| 44 | + |
| 45 | + pub struct MakeServiceFn<F>(pub F); |
| 46 | + pub struct ServiceFn<F, R>(pub PhantomData<(F, R)>); |
| 47 | + |
| 48 | + pub trait Service<Request> { |
| 49 | + type Response; |
| 50 | + } |
| 51 | + |
| 52 | + impl<'t, F, Ret, Target, Svc> Service<&'t Target> for MakeServiceFn<F> |
| 53 | + where |
| 54 | + F: Fn() -> Ret, |
| 55 | + Ret: Future<Output = Result<Svc, ()>>, |
| 56 | + { |
| 57 | + type Response = Svc; |
| 58 | + } |
| 59 | + |
| 60 | + impl<F, ReqBody, Ret, ResBody, E> Service<ReqBody> for ServiceFn<F, ReqBody> |
| 61 | + where |
| 62 | + F: Fn() -> Ret, |
| 63 | + Ret: Future<Output = Result<ResBody, E>>, |
| 64 | + { |
| 65 | + type Response = ResBody; |
| 66 | + } |
| 67 | +} |
| 68 | + |
| 69 | +async fn smarvice() -> Result<(), ()> { |
| 70 | + Ok(()) |
| 71 | +} |
| 72 | + |
| 73 | +fn service_fn<F, R, S>(f: F) -> hyper::ServiceFn<F, R> |
| 74 | +where |
| 75 | + F: Fn() -> S, |
| 76 | +{ |
| 77 | + hyper::ServiceFn(std::marker::PhantomData) |
| 78 | +} |
| 79 | + |
| 80 | +async fn iceice() { |
| 81 | + let service = hyper::MakeServiceFn(|| async { Ok::<_, ()>(service_fn(|| smarvice())) }); |
| 82 | + hyper::serve::<(), _>(service).await; |
| 83 | +} |
| 84 | + |
| 85 | +fn main() {} |
0 commit comments