use std::{fs::File, io, process::Stdio, sync::Arc};
#[derive(Debug, Clone)]
pub enum OutDest {
Pipe,
Capture,
Null,
Inherit,
File(Arc<File>), }
impl From<File> for OutDest {
fn from(file: File) -> Self {
Arc::new(file).into()
}
}
impl From<Arc<File>> for OutDest {
fn from(file: Arc<File>) -> Self {
Self::File(file)
}
}
impl TryFrom<&OutDest> for Stdio {
type Error = io::Error;
fn try_from(out_dest: &OutDest) -> Result<Self, Self::Error> {
match out_dest {
OutDest::Pipe | OutDest::Capture => Ok(Self::piped()),
OutDest::Null => Ok(Self::null()),
OutDest::Inherit => Ok(Self::inherit()),
OutDest::File(file) => Ok(file.try_clone()?.into()),
}
}
}