Skip to main content

base_http/body/
empty.rs

1// Released under the MIT License.
2// Copyright, 2026, by Samuel Williams.
3
4use super::{BodyFrame, ReadableBody};
5use base_scheduler::{Cancellation, Cancelled};
6
7/// A ready body with no data and a representation length of zero.
8#[derive(Clone, Copy, Debug, Default)]
9pub struct EmptyBody;
10
11impl ReadableBody for EmptyBody {
12    type Data = Vec<u8>;
13    type Error = Cancelled;
14
15    fn may_have_trailers(&self) -> bool {
16        false
17    }
18
19    fn is_ready(&self) -> bool {
20        true
21    }
22
23    fn is_empty(&self) -> bool {
24        true
25    }
26
27    fn length(&self) -> Option<u64> {
28        Some(0)
29    }
30
31    fn close(&mut self, _error: Option<Self::Error>) {}
32
33    async fn read(
34        &mut self,
35        cancellation: &Cancellation,
36    ) -> Result<BodyFrame<Self::Data>, Self::Error> {
37        cancellation.check()?;
38        Ok(BodyFrame::End)
39    }
40}