use filedesc::FileDesc;
pub struct UnixBody {
pub data: Vec<u8>,
pub fds: Vec<FileDesc>,
}
impl UnixBody {
pub fn new<Data, FileDescs>(data: Data, fds: FileDescs) -> Self
where
Vec<u8>: From<Data>,
Vec<FileDesc>: From<FileDescs>,
{
Self {
data: data.into(),
fds: fds.into(),
}
}
}
impl crate::Body for UnixBody {
fn empty() -> Self {
Self::from(Vec::new())
}
fn from_error(message: &str) -> Self {
Self::from(message.as_bytes())
}
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 From<Vec<u8>> for UnixBody {
fn from(other: Vec<u8>) -> Self {
Self {
data: other,
fds: Vec::new(),
}
}
}
impl<'a> From<&'a [u8]> for UnixBody {
fn from(other: &'a [u8]) -> Self {
Box::<[u8]>::from(other).into()
}
}
impl From<Box<[u8]>> for UnixBody {
fn from(other: Box<[u8]>) -> Self {
Vec::from(other).into()
}
}
impl<Data, FileDescs> From<(Data, FileDescs)> for UnixBody
where
Vec<u8>: From<Data>,
Vec<FileDesc>: From<FileDescs>,
{
fn from(other: (Data, FileDescs)) -> Self {
let (data, fds) = other;
Self::new(data, fds)
}
}