1use super::{Body, SizeHint};
2use bytes::Buf;
3use http::HeaderMap;
4use std::{
5 convert::Infallible,
6 fmt,
7 marker::PhantomData,
8 pin::Pin,
9 task::{Context, Poll},
10};
11
12/// A body that is always empty.
13pub struct Empty<D> {
14 _marker: PhantomData<fn() -> D>,
15}
16
17impl<D> Empty<D> {
18 /// Create a new `Empty`.
19 pub fn new() -> Self {
20 Self::default()
21 }
22}
23
24impl<D: Buf> Body for Empty<D> {
25 type Data = D;
26 type Error = Infallible;
27
28 #[inline]
29 fn poll_data(
30 self: Pin<&mut Self>,
31 _cx: &mut Context<'_>,
32 ) -> Poll<Option<Result<Self::Data, Self::Error>>> {
33 Poll::Ready(None)
34 }
35
36 #[inline]
37 fn poll_trailers(
38 self: Pin<&mut Self>,
39 _cx: &mut Context<'_>,
40 ) -> Poll<Result<Option<HeaderMap>, Self::Error>> {
41 Poll::Ready(Ok(None))
42 }
43
44 fn is_end_stream(&self) -> bool {
45 true
46 }
47
48 fn size_hint(&self) -> SizeHint {
49 SizeHint::with_exact(0)
50 }
51}
52
53impl<D> fmt::Debug for Empty<D> {
54 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
55 f.debug_struct(name:"Empty").finish()
56 }
57}
58
59impl<D> Default for Empty<D> {
60 fn default() -> Self {
61 Self {
62 _marker: PhantomData,
63 }
64 }
65}
66
67impl<D> Clone for Empty<D> {
68 fn clone(&self) -> Self {
69 Self {
70 _marker: PhantomData,
71 }
72 }
73}
74
75impl<D> Copy for Empty<D> {}
76