#[derive(Debug, Clone)]
pub struct StreamBody {
pub data: Vec<u8>,
}
impl StreamBody {
fn new(data: Vec<u8>) -> Self {
Self { data }
}
}
impl crate::Body for StreamBody {
fn empty() -> Self {
Self::new(Vec::new())
}
fn from_error(message: &str) -> Self {
Self::new(message.as_bytes().into())
}
fn as_error(&self) -> Result<&str, std::str::Utf8Error> {
std::str::from_utf8(&self.data)
}
fn into_error(self) -> Result<String, std::string::FromUtf8Error> {
String::from_utf8(self.data)
}
}
impl<T> From<T> for StreamBody
where
Vec<u8>: From<T>,
{
fn from(other: T) -> Self {
Self { data: other.into() }
}
}
impl AsRef<[u8]> for StreamBody {
fn as_ref(&self) -> &[u8] {
&self.data
}
}
impl std::ops::Deref for StreamBody {
type Target = [u8];
fn deref(&self) -> &[u8] {
&self.data
}
}