async_chunked_transfer/lib.rs
1// Copyright 2015 The tiny-http Contributors
2// Copyright 2015 The rust-chunked-transfer Contributors
3//
4// Licensed under the Apache License, Version 2.0 (the "License");
5// you may not use this file except in compliance with the License.
6// You may obtain a copy of the License at
7//
8// http://www.apache.org/licenses/LICENSE-2.0
9//
10// Unless required by applicable law or agreed to in writing, software
11// distributed under the License is distributed on an "AS IS" BASIS,
12// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13// See the License for the specific language governing permissions and
14// limitations under the License.
15
16mod decoder;
17pub use crate::decoder::Decoder;
18
19mod encoder;
20pub use crate::encoder::Encoder;
21
22use std::task::{Context, Poll};
23pub(crate) fn poll_fn<T, F>(f: F) -> PollFn<F>
24where
25 F: FnMut(&mut Context<'_>) -> Poll<T>,
26{
27 PollFn { f }
28}
29
30pub(crate) struct PollFn<F> {
31 f: F,
32}
33
34impl<F> Unpin for PollFn<F> {}
35
36impl<T, F> std::future::Future for PollFn<F>
37where
38 F: FnMut(&mut Context<'_>) -> Poll<T>,
39{
40 type Output = T;
41
42 fn poll(mut self: std::pin::Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<T> {
43 (&mut self.f)(cx)
44 }
45}