#[cfg(unix)]
use crate::OwnedFd;
use std::ops::Deref;
use crate::serialized::Context;
#[derive(Debug)]
pub struct Written {
size: usize,
context: Context,
#[cfg(unix)]
fds: Vec<OwnedFd>,
}
impl Written {
pub fn new(size: usize, context: Context) -> Self {
Self {
size,
context,
#[cfg(unix)]
fds: vec![],
}
}
#[cfg(unix)]
pub fn set_fds(mut self, fds: impl IntoIterator<Item = impl Into<OwnedFd>>) -> Self {
self.fds = fds.into_iter().map(Into::into).collect();
self
}
pub fn size(&self) -> usize {
self.size
}
pub fn context(&self) -> Context {
self.context
}
#[cfg(unix)]
pub fn into_fds(self) -> Vec<OwnedFd> {
self.fds
}
#[cfg(unix)]
pub fn fds(&self) -> &[OwnedFd] {
&self.fds
}
}
impl Deref for Written {
type Target = usize;
fn deref(&self) -> &Self::Target {
&self.size
}
}