1 // Regression test for #61320
2 // This is the same issue as #61311, just a larger test case.
6 pub struct AndThen<A, B, F>
11 state: (A, B::Future, F),
14 pub struct FutureResult<T, E> {
15 inner: Option<Result<T, E>>,
18 impl<T, E> Future for FutureResult<T, E> {
22 fn poll(&mut self) -> Poll<T, E> {
27 pub type Poll<T, E> = Result<T, E>;
29 impl<A, B, F> Future for AndThen<A, B, F>
32 B: IntoFuture<Error = A::Error>,
33 F: FnOnce(A::Item) -> B,
36 type Error = B::Error;
38 fn poll(&mut self) -> Poll<B::Item, B::Error> {
48 fn poll(&mut self) -> Poll<Self::Item, Self::Error>;
50 fn and_then<F, B>(self, f: F) -> AndThen<Self, B, F>
52 F: FnOnce(Self::Item) -> B,
53 B: IntoFuture<Error = Self::Error>,
60 pub trait IntoFuture {
61 /// The future that this type can be converted into.
62 type Future: Future<Item = Self::Item, Error = Self::Error>;
64 /// The item that the future may resolve with.
66 /// The error that the future may resolve with.
69 /// Consumes this object and produces a future.
70 fn into_future(self) -> Self::Future;
73 impl<F: Future> IntoFuture for F {
76 type Error = F::Error;
78 fn into_future(self) -> F {
83 impl<F: ?Sized + Future> Future for ::std::boxed::Box<F> {
85 type Error = F::Error;
87 fn poll(&mut self) -> Poll<Self::Item, Self::Error> {
92 impl<T, E> IntoFuture for Result<T, E> {
93 type Future = FutureResult<T, E>;
97 fn into_future(self) -> FutureResult<T, E> {
102 struct Request<T>(T);
104 trait RequestContext {}
105 impl<T> RequestContext for T {}
107 impl AsRef<NoContext> for NoContext {
108 fn as_ref(&self) -> &Self {
113 type BoxedError = Box<dyn std::error::Error + Send + Sync>;
114 type DefaultFuture<T, E> = Box<dyn Future<Item = T, Error = E> + Send>;
117 type Result: IntoFuture<Item = Self, Error = BoxedError>;
118 fn from_request(request: &Request<()>) -> Self::Result;
121 trait FromRequest: Sized {
123 type Future: Future<Item = Self, Error = BoxedError> + Send;
124 fn from_request(request: Request<()>) -> Self::Future;
128 impl Guard for MyGuard {
129 type Result = Result<Self, BoxedError>;
130 fn from_request(_request: &Request<()>) -> Self::Result {
139 impl<I> FromRequest for Generic<I>
142 <MyGuard as Guard>::Result: IntoFuture<Item = MyGuard, Error = BoxedError>,
143 <<MyGuard as Guard>::Result as IntoFuture>::Future: Send,
144 I: FromRequest<Context = NoContext>,
146 type Future = DefaultFuture<Self, BoxedError>;
147 type Context = NoContext;
148 fn from_request(headers: Request<()>) -> DefaultFuture<Self, BoxedError> {
149 let _future = <MyGuard as Guard>::from_request(&headers)
152 <I as FromRequest>::from_request(headers)
154 .and_then(move |fld_inner| Ok(Generic { _inner: fld_inner }).into_future())