process: Add back in 0.1.0 compatibility layer

This commit is contained in:
Alex Crichton
2019-06-24 16:56:48 -07:00
committed by Ivan Petkov
parent f3f99b723f
commit ca51ae9651
+103 -2
View File
@@ -99,8 +99,10 @@ extern crate mio;
#[macro_use]
extern crate log;
use std::ffi::OsStr;
use std::io::{self, Read, Write};
use std::process::{ExitStatus, Command, Output, Stdio};
use std::path::Path;
use std::process::{self, ExitStatus, Output, Stdio};
use futures::{Future, Poll, IntoFuture};
use futures::future::{Flatten, FutureResult, Either, ok};
@@ -183,7 +185,7 @@ pub trait CommandExt {
}
impl CommandExt for Command {
impl CommandExt for process::Command {
fn spawn_async(&mut self, handle: &Handle) -> io::Result<Child> {
let mut child = Child {
child: imp::Child::new(try!(self.spawn()), handle),
@@ -441,3 +443,102 @@ impl Read for ChildStderr {
self.inner.read(bytes)
}
}
// deprecated from 0.1.0
#[deprecated(note = "use std::process::Command instead")]
#[allow(deprecated, missing_docs)]
pub struct Command {
inner: process::Command,
#[allow(dead_code)]
handle: Handle,
}
#[deprecated(note = "use std::process::Command instead")]
#[allow(deprecated, missing_docs)]
pub struct Spawn {
inner: Box<Future<Item=Child, Error=io::Error>>,
}
#[deprecated(note = "use std::process::Command instead")]
#[allow(deprecated, missing_docs)]
impl Command {
pub fn new<T: AsRef<OsStr>>(exe: T, handle: &Handle) -> Command {
Command::_new(exe.as_ref(), handle)
}
fn _new(exe: &OsStr, handle: &Handle) -> Command {
Command {
inner: process::Command::new(exe),
handle: handle.clone(),
}
}
pub fn arg<S: AsRef<OsStr>>(&mut self, arg: S) -> &mut Command {
self._arg(arg.as_ref())
}
fn _arg(&mut self, arg: &OsStr) -> &mut Command {
self.inner.arg(arg);
self
}
pub fn args<S: AsRef<OsStr>>(&mut self, args: &[S]) -> &mut Command {
for arg in args {
self._arg(arg.as_ref());
}
self
}
pub fn env<K, V>(&mut self, key: K, val: V) -> &mut Command
where K: AsRef<OsStr>, V: AsRef<OsStr>
{
self._env(key.as_ref(), val.as_ref())
}
fn _env(&mut self, key: &OsStr, val: &OsStr) -> &mut Command {
self.inner.env(key, val);
self
}
pub fn env_remove<K: AsRef<OsStr>>(&mut self, key: K) -> &mut Command {
self._env_remove(key.as_ref())
}
fn _env_remove(&mut self, key: &OsStr) -> &mut Command {
self.inner.env_remove(key);
self
}
pub fn env_clear(&mut self) -> &mut Command {
self.inner.env_clear();
self
}
pub fn current_dir<P: AsRef<Path>>(&mut self, dir: P) -> &mut Command {
self._current_dir(dir.as_ref())
}
fn _current_dir(&mut self, dir: &Path) -> &mut Command {
self.inner.current_dir(dir);
self
}
pub fn spawn(mut self) -> Spawn {
Spawn {
inner: self.inner.spawn_async(&self.handle).into_future().boxed()
}
}
}
#[deprecated(note = "use std::process::Command instead")]
#[allow(deprecated)]
impl Future for Spawn {
type Item = Child;
type Error = io::Error;
fn poll(&mut self) -> Poll<Child, io::Error> {
self.inner.poll()
}
}