use std::{
io::Result,
process::{ExitStatus, Output},
};
use super::AsyncGroupChild;
use tokio::process::Child;
#[derive(Debug)]
pub enum ErasedChild {
Grouped(AsyncGroupChild),
Ungrouped(Child),
}
impl ErasedChild {
pub fn id(&mut self) -> Option<u32> {
match self {
Self::Grouped(c) => c.id(),
Self::Ungrouped(c) => c.id(),
}
}
pub async fn kill(&mut self) -> Result<()> {
match self {
Self::Grouped(c) => c.kill().await,
Self::Ungrouped(c) => c.kill().await,
}
}
pub fn start_kill(&mut self) -> Result<()> {
match self {
Self::Grouped(c) => c.start_kill(),
Self::Ungrouped(c) => c.start_kill(),
}
}
pub fn try_wait(&mut self) -> Result<Option<ExitStatus>> {
match self {
Self::Grouped(c) => c.try_wait(),
Self::Ungrouped(c) => c.try_wait(),
}
}
pub async fn wait(&mut self) -> Result<ExitStatus> {
match self {
Self::Grouped(c) => c.wait().await,
Self::Ungrouped(c) => c.wait().await,
}
}
pub async fn wait_with_output(self) -> Result<Output> {
match self {
Self::Grouped(c) => c.wait_with_output().await,
Self::Ungrouped(c) => c.wait_with_output().await,
}
}
#[cfg(unix)]
pub fn signal(&self, sig: crate::Signal) -> Result<()> {
use crate::UnixChildExt;
match self {
Self::Grouped(c) => c.signal(sig),
Self::Ungrouped(c) => c.signal(sig),
}
}
}