#[derive(Debug, Default)]
pub struct Body {
bytes: Vec<u8>,
}
impl Body {
pub fn empty() -> Self {
Self::default()
}
pub fn from_bytes(bytes: impl Into<Vec<u8>>) -> Self {
Self {
bytes: bytes.into(),
}
}
pub fn as_bytes(&self) -> &[u8] {
&self.bytes
}
pub fn len(&self) -> usize {
self.bytes.len()
}
pub fn is_empty(&self) -> bool {
self.bytes.is_empty()
}
pub fn into_bytes(self) -> Vec<u8> {
self.bytes
}
}
impl From<Vec<u8>> for Body {
fn from(bytes: Vec<u8>) -> Self {
Self::from_bytes(bytes)
}
}
impl From<&[u8]> for Body {
fn from(bytes: &[u8]) -> Self {
Self::from_bytes(bytes)
}
}
impl From<String> for Body {
fn from(value: String) -> Self {
Self::from_bytes(value.into_bytes())
}
}
impl From<&str> for Body {
fn from(value: &str) -> Self {
Self::from_bytes(value.as_bytes())
}
}