Skip to content

Commit dae020d

Browse files
authored
Rollup merge of #74192 - xkr47:patch-1, r=Mark-Simulacrum
Improve documentation on process::Child.std* fields As a relative beginner, it took a while for me to figure out I could just steal the references to avoid partially moving the child and thus retain ability to call functions on it (and store it in structs etc).
2 parents 3111a8c + 90e4c90 commit dae020d

File tree

1 file changed

+24
-3
lines changed

1 file changed

+24
-3
lines changed

library/std/src/process.rs

+24-3
Original file line numberDiff line numberDiff line change
@@ -170,17 +170,38 @@ pub struct Child {
170170
handle: imp::Process,
171171

172172
/// The handle for writing to the child's standard input (stdin), if it has
173-
/// been captured.
173+
/// been captured. To avoid partially moving
174+
/// the `child` and thus blocking yourself from calling
175+
/// functions on `child` while using `stdin`,
176+
/// you might find it helpful:
177+
///
178+
/// ```compile_fail,E0425
179+
/// let stdin = child.stdin.take().unwrap();
180+
/// ```
174181
#[stable(feature = "process", since = "1.0.0")]
175182
pub stdin: Option<ChildStdin>,
176183

177184
/// The handle for reading from the child's standard output (stdout), if it
178-
/// has been captured.
185+
/// has been captured. You might find it helpful to do
186+
///
187+
/// ```compile_fail,E0425
188+
/// let stdout = child.stdout.take().unwrap();
189+
/// ```
190+
///
191+
/// to avoid partially moving the `child` and thus blocking yourself from calling
192+
/// functions on `child` while using `stdout`.
179193
#[stable(feature = "process", since = "1.0.0")]
180194
pub stdout: Option<ChildStdout>,
181195

182196
/// The handle for reading from the child's standard error (stderr), if it
183-
/// has been captured.
197+
/// has been captured. You might find it helpful to do
198+
///
199+
/// ```compile_fail,E0425
200+
/// let stderr = child.stderr.take().unwrap();
201+
/// ```
202+
///
203+
/// to avoid partially moving the `child` and thus blocking yourself from calling
204+
/// functions on `child` while using `stderr`.
184205
#[stable(feature = "process", since = "1.0.0")]
185206
pub stderr: Option<ChildStderr>,
186207
}

0 commit comments

Comments
 (0)