1use bytes::Buf;
2use http_body::{Body, Frame, SizeHint};
3use std::{
4 convert::Infallible,
5 fmt,
6 marker::PhantomData,
7 pin::Pin,
8 task::{Context, Poll},
9};
10
11pub struct Empty<D> {
13 _marker: PhantomData<fn() -> D>,
14}
15
16impl<D> Empty<D> {
17 pub fn new() -> Self {
19 Self::default()
20 }
21}
22
23impl<D: Buf> Body for Empty<D> {
24 type Data = D;
25 type Error = Infallible;
26
27 #[inline]
28 fn poll_frame(
29 self: Pin<&mut Self>,
30 _cx: &mut Context<'_>,
31 ) -> Poll<Option<Result<Frame<Self::Data>, Self::Error>>> {
32 Poll::Ready(None)
33 }
34
35 fn is_end_stream(&self) -> bool {
36 true
37 }
38
39 fn size_hint(&self) -> SizeHint {
40 SizeHint::with_exact(0)
41 }
42}
43
44impl<D> fmt::Debug for Empty<D> {
45 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
46 f.debug_struct("Empty").finish()
47 }
48}
49
50impl<D> Default for Empty<D> {
51 fn default() -> Self {
52 Self {
53 _marker: PhantomData,
54 }
55 }
56}
57
58impl<D> Clone for Empty<D> {
59 fn clone(&self) -> Self {
60 *self
61 }
62}
63
64impl<D> Copy for Empty<D> {}