diff --git a/tokio/CHANGELOG.md b/tokio/CHANGELOG.md index 27f84c867f4..9e1b7f1a57e 100644 --- a/tokio/CHANGELOG.md +++ b/tokio/CHANGELOG.md @@ -4,6 +4,12 @@ This fixes a regression on the wasm32-unknown-unknown target, where code that previously did not panic due to calls to `Instant::now()` started failing. This is due to the stabilization of the first time-based metric. +### Added + +- process: Implement `TryFrom` for `tokio::process::Child` ([#7388]) + +[#7388]: https://github.com/tokio-rs/tokio/pull/7388 + ### Fixed - Disable time-based metrics on wasm32-unknown-unknown ([#7322]) diff --git a/tokio/src/process/mod.rs b/tokio/src/process/mod.rs index eba17cff3a7..402a56d8d1b 100644 --- a/tokio/src/process/mod.rs +++ b/tokio/src/process/mod.rs @@ -1212,6 +1212,24 @@ pub struct Child { pub stderr: Option, } +impl TryFrom for Child { + type Error = io::Error; + + fn try_from(value: StdChild) -> io::Result { + let spawned_child = imp::build_child(value)?; + + Ok(Child { + child: FusedChild::Child(ChildDropGuard { + inner: spawned_child.child, + kill_on_drop: false, + }), + stdin: spawned_child.stdin.map(|inner| ChildStdin { inner }), + stdout: spawned_child.stdout.map(|inner| ChildStdout { inner }), + stderr: spawned_child.stderr.map(|inner| ChildStderr { inner }), + }) + } +} + impl Child { /// Returns the OS-assigned process identifier associated with this child /// while it is still running.