use crate::{Error, Transport};
use futures_lite::AsyncRead;
use trillium_http::ReceivedBody;
use trillium_macros::AsyncRead;
#[derive(AsyncRead, Debug)]
pub struct RequestBody<'a>(ReceivedBody<'a, Box<dyn Transport>>);
impl RequestBody<'_> {
pub async fn read_bytes(self) -> Result<Vec<u8>, Error> {
self.0.read_bytes().await
}
pub async fn read_string(self) -> Result<String, Error> {
self.0.read_string().await
}
#[must_use]
pub fn with_max_len(mut self, max_len: u64) -> Self {
self.0.set_max_len(max_len);
self
}
pub fn set_max_len(&mut self, max_len: u64) -> &mut Self {
self.0.set_max_len(max_len);
self
}
pub fn content_length(&self) -> Option<u64> {
self.0.content_length()
}
}
impl<'a> From<RequestBody<'a>> for ReceivedBody<'a, Box<dyn Transport>> {
fn from(value: RequestBody<'a>) -> Self {
value.0
}
}
impl<'a> From<ReceivedBody<'a, Box<dyn Transport>>> for RequestBody<'a> {
fn from(received_body: ReceivedBody<'a, Box<dyn Transport>>) -> Self {
Self(received_body)
}
}