Repository: tokio-rs/tokio
File: tokio/src/process/mod.rs (Rust)

Code before:
    /// let parent_process_handle = parent.as_raw_handle();
    ///
    /// const PROC_THREAD_ATTRIBUTE_PARENT_PROCESS: usize = 0x00020000;
    /// let mut attribute_list = ProcThreadAttributeList::build()
    ///     .attribute(PROC_THREAD_ATTRIBUTE_PARENT_PROCESS, &parent_process_handle)
    ///     .finish()
    ///     .unwrap();
    ///
    /// let output = Command::new("ls")
    ///         .stdin(Stdio::null())
    ///         .stdout(Stdio::piped())
    ///         .stderr(Stdio::piped())
    ///         .spawn_with(|cmd| cmd.spawn_with_attributes(&attribute_list))
    ///         .unwrap()
    ///         .wait_with_output()
    ///         .await
    ///         .unwrap();
    /// # }
    /// ```
    #[cfg(tokio_unstable)]
    #[inline]
    pub fn spawn_with(
        &mut self,
        with: impl Fn(&mut StdCommand) -> io::Result<StdChild>,
    ) -> io::Result<Child> {
        // On two lines to circumvent a mutable borrow check failure.
        let child = with(&mut self.std)?;
        self.build_child(child)
    }

    /// Small indirection for the spawn implementations.
    ///
    /// This is introduced for [`Self::spawn`] and [`Self::spawn_with`] to use:
    /// [`Self::spawn`] cannot depend directly on on [`Self::spawn_with`] since
    /// it is behind `tokio_unstable`. It also serves as a way to reduce
    /// monomorphization bloat by taking in an already-spawned child process
    /// instead of a command and custom spawn function.
    fn build_child(&self, child: StdChild) -> io::Result<Child> {
        let spawned_child = imp::build_child(child)?;

        Ok(Child {
            child: FusedChild::Child(ChildDropGuard {
                inner: spawned_child.child,
                kill_on_drop: self.kill_on_drop,
            }),
            stdin: spawned_child.stdin.map(|inner| ChildStdin { inner }),
            stdout: spawned_child.stdout.map(|inner| ChildStdout { inner }),
            stderr: spawned_child.stderr.map(|inner| ChildStderr { inner }),
        })
    }


Review comment (suggestion):
This is missing the "Available on `tokio_unstable` only" marker in the docs.
```rs
#[cfg_attr(docsrs, doc(cfg(tokio_unstable)))]
```

Code after:
    /// let parent_process_handle = parent.raw_handle();
    ///
    /// const PROC_THREAD_ATTRIBUTE_PARENT_PROCESS: usize = 0x00020000;
    /// let attribute_list = ProcThreadAttributeList::build()
    ///     .attribute(PROC_THREAD_ATTRIBUTE_PARENT_PROCESS, &parent_process_handle)
    ///     .finish()
    ///     .unwrap();
    ///
    /// let _output = Command::new("ls")
    ///     .stdin(Stdio::null())
    ///     .stdout(Stdio::piped())
    ///     .stderr(Stdio::piped())
    ///     .spawn_with(|cmd| cmd.spawn_with_attributes(&attribute_list))
    ///     .unwrap()
    ///     .wait_with_output()
    ///     .await
    ///     .unwrap();
    /// # }
    /// ```
    #[cfg(tokio_unstable)]
    #[cfg_attr(docsrs, doc(cfg(tokio_unstable)))]
    #[inline]
    pub fn spawn_with(
        &mut self,
        with: impl Fn(&mut StdCommand) -> io::Result<StdChild>,
    ) -> io::Result<Child> {
        // On two lines to circumvent a mutable borrow check failure.
        let child = with(&mut self.std)?;
        self.build_child(child)
    }

    /// Small indirection for the spawn implementations.
    ///
    /// This is introduced for [`Self::spawn`] and [`Self::spawn_with`] to use:
    /// [`Self::spawn`] cannot depend directly on on [`Self::spawn_with`] since
    /// it is behind `tokio_unstable`. It also serves as a way to reduce
    /// monomorphization bloat by taking in an already-spawned child process
    /// instead of a command and custom spawn function.
    fn build_child(&self, child: StdChild) -> io::Result<Child> {
        let spawned_child = imp::build_child(child)?;

        Ok(Child {
            child: FusedChild::Child(ChildDropGuard {
                inner: spawned_child.child,
                kill_on_drop: self.kill_on_drop,
            }),
            stdin: spawned_child.stdin.map(|inner| ChildStdin { inner }),
            stdout: spawned_child.stdout.map(|inner| ChildStdout { inner }),
            stderr: spawned_child.stderr.map(|inner| ChildStderr { inner }),
        })
    }