-
Notifications
You must be signed in to change notification settings - Fork 12.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Documents From
implementations for Stdio
#55200
Conversation
Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @kennytm (or someone else) soon. If any changes to this PR are deemed necessary, please add them as extra commits. This ensures that the reviewer can see what has changed since they last reviewed the code. Due to the way GitHub handles out-of-date commits, this should also make it reasonably obvious what issues have or haven't been addressed. Large or tricky changes may require several passes of review and changes. Please see the contribution instructions for more information. |
Thanks for the PR! I think the documentation should better illustrate what you could do with the converted fs::write("foo.txt", b"Hello, world!")?;
let file = File::open("foo.txt")?;
let output = Command::new("rev")
.stdin(Stdio::from(file)) // convert the File into a Stdio
.output()?;
assert_eq!(output.stdout, b"!dlrow ,olleH"); Note that our examples only used |
Is |
Is something like the following will be OK for the other examples? use std::process::{Command, Stdio};
let hello = Command::new("echo")
.arg("Hello, world!")
.stdout(Stdio::piped())
.spawn()
.expect("failed echo command");
let reverse = Command::new("rev")
.stdin(Stdio::from(hello.stdout.unwrap())) // convert the standard input into a Stdio
.output()
.expect("failed reverse command");
assert_eq!(reverse.stdout, b"!dlrow ,olleH\n"); This work without the explicit |
The job Click to expand the log.
I'm a bot! I can only do what humans tell me to, so if this was not helpful or you have suggestions for improvements, please ping or otherwise contact |
@octronics That looks fine. Doc code blocks doesn't implicitly support /// ```rust
/// use std::fs::File;
///
/// # fn main() -> std::io::Result<()> {
/// let f = File::open("src/lib.rs")?;
/// # Ok(()) }
/// ``` |
Build failure is caused by read-only filesystems on CI. So will add The fn work_with_stdio(io: Stdio) {}
var file = File::open("foo.txt").unwrap();
work_with_stdio(Stdio::from(file)); Any idea about code that will need explicit conversion? |
@octronics The main purpose of the let file = File::open("foo.txt")?;
let output = Command::new("rev")
.stdin(file)
.output()?; and add a paragraph before the example explaining that |
Will do that. Thanks. |
Is use std::process::{Command, Stdio};
let reverse = Command::new("rev")
.arg("non_existing_file.txt")
.stderr(Stdio::piped())
.spawn()
.expect("failed reverse command");
let cat = Command::new("cat")
.arg("-")
.stdin(reverse.stderr.unwrap()) // Converted into a Stdio here
.output()
.expect("failed echo command");
assert_eq!(
String::from_utf8_lossy(&cat.stdout),
"rev: cannot open non_existing_file.txt: No such file or directory\n"
); If it is not available, I will declare the code block as |
@oconnor663 No, but you could just feed it into another The error message from Windows is likely different though. Perhaps just remove the |
What do you think declaring the code blocks as |
The job Click to expand the log.
I'm a bot! I can only do what humans tell me to, so if this was not helpful or you have suggestions for improvements, please ping or otherwise contact |
The job Click to expand the log.
I'm a bot! I can only do what humans tell me to, so if this was not helpful or you have suggestions for improvements, please ping or otherwise contact |
@octronics Yes. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
r=me after this is fixed and all commits squashed into a single commit.
Add a basic summary and an example to From `ChildStdin`, `ChildStdout`, `ChildStderr`, `File` implementations.
Squashed and rebase on top of current master. |
Thank you! @bors r+ rollup |
📌 Commit 0b82e03 has been approved by |
Documents `From` implementations for `Stdio` This PR solves part of rust-lang#51430 by adding a basic summary and an example to each `impl From` inside `process` module (`ChildStdin`, `ChildStdout`, `ChildStderr`, `File`). It does not document if the conversions allocate memory and how expensive they are.
Documents `From` implementations for `Stdio` This PR solves part of rust-lang#51430 by adding a basic summary and an example to each `impl From` inside `process` module (`ChildStdin`, `ChildStdout`, `ChildStderr`, `File`). It does not document if the conversions allocate memory and how expensive they are.
Rollup of 22 pull requests Successful merges: - #53507 (Add doc for impl From for Waker) - #53931 (Gradually expanding libstd's keyword documentation) - #54965 (update tcp stream documentation) - #54977 (Accept `Option<Box<$t:ty>>` in macro argument) - #55138 (in which unused-parens suggestions heed what the user actually wrote) - #55173 (Suggest appropriate syntax on missing lifetime specifier in return type) - #55200 (Documents `From` implementations for `Stdio`) - #55245 (submodules: update clippy from 5afdf8b to b1d0343) - #55247 (Clarified code example in char primitive doc) - #55251 (Fix a typo in the documentation of RangeInclusive) - #55253 (only issue "variant of the expected type" suggestion for enums) - #55254 (Correct trailing ellipsis in name_from_pat) - #55269 (fix typos in various places) - #55282 (Remove redundant clone) - #55285 (Do some copy editing on the release notes) - #55291 (Update stdsimd submodule) - #55296 (Set RUST_BACKTRACE=0 for rustdoc-ui/failed-doctest-output.rs) - #55306 (Regression test for #54478.) - #55328 (Fix doc for new copysign functions) - #55340 (Operands no longer appear in places) - #55345 (Remove is_null) - #55348 (Update RELEASES.md after destabilization of non_modrs_mods) Failed merges: r? @ghost
This PR solves part of #51430 by adding a basic summary and an example to each
impl From
insideprocess
module (ChildStdin
,ChildStdout
,ChildStderr
,File
).It does not document if the conversions allocate memory and how expensive they are.