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 const fn new() -> Self {
19 Self {
20 _marker: PhantomData,
21 }
22 }
23}
24
25impl<D: Buf> Body for Empty<D> {
26 type Data = D;
27 type Error = Infallible;
28
29 #[inline]
30 fn poll_frame(
31 self: Pin<&mut Self>,
32 _cx: &mut Context<'_>,
33 ) -> Poll<Option<Result<Frame<Self::Data>, Self::Error>>> {
34 Poll::Ready(None)
35 }
36
37 fn is_end_stream(&self) -> bool {
38 true
39 }
40
41 fn size_hint(&self) -> SizeHint {
42 SizeHint::with_exact(0)
43 }
44}
45
46impl<D> fmt::Debug for Empty<D> {
47 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
48 f.debug_struct("Empty").finish()
49 }
50}
51
52impl<D> Default for Empty<D> {
53 fn default() -> Self {
54 Self::new()
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> {}