-
Notifications
You must be signed in to change notification settings - Fork 13.2k
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
Add missing links and examples for FileExt #45631
Conversation
src/libstd/sys/unix/ext/fs.rs
Outdated
/// file.write_at(b"sushi", 10); | ||
/// # Ok(()) | ||
/// # } | ||
/// ``` |
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.
[00:03:41] tidy error: /checkout/src/libstd/sys/unix/ext/fs.rs:90: trailing whitespace
09c501f
to
376f8dc
Compare
Updated. |
src/libstd/sys/unix/ext/fs.rs
Outdated
/// let file = File::open("foo.txt")?; | ||
/// | ||
/// // We now read 8 bytes from the offset 10. | ||
/// file.read_at(buf, 10); |
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.
What do you think about adding ?
at the end of the method call instead of ignoring the result?
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.
I could just remove the ';'.
376f8dc
to
8382304
Compare
src/libstd/sys/unix/ext/fs.rs
Outdated
/// short write. | ||
/// | ||
/// [`File::write`]: ../../../std/fs/struct.File.html#write.v |
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.
Broken link, needs one more ../
.
[01:13:11] std/os/unix/fs/trait.FileExt.html:70: broken link - std/std/fs/struct.File.html
[01:13:11] std/os/unix/fs/trait.FileExt.html:95: broken link - std/std/fs/struct.File.html
[01:13:20] thread 'main' panicked at 'found some broken links', /checkout/src/tools/linkchecker/main.rs:49:8
[01:13:20] note: Run with `RUST_BACKTRACE=1` for a backtrace.
8382304
to
8892230
Compare
src/libstd/sys/unix/ext/fs.rs
Outdated
/// let buf = &mut [0u8; 8]; | ||
/// let file = File::open("foo.txt")?; | ||
/// | ||
/// // We now read 8 bytes from the offset 10. |
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.
This will only read up to 8 bytes so I think it's important to do something with the value read_at
returns in this example. The same goes for write_at
.
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.
Good point.
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.
maybe something like this?
// Read up to 8 bytes from the offset 10.
let num_bytes_read = file.read_at(buf, 10)?;
println!("read {} bytes: {:?}", num_bytes_read, buf);
r? @frewsxcv |
src/libstd/sys/unix/ext/fs.rs
Outdated
/// | ||
/// # use std::io; | ||
/// # fn f() -> io::Result<()> { | ||
/// let buf = &mut [0u8; 8]; |
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.
Can you make this let mut buf = [0u8; 8];
and pass &mut buf
to read_at
? That way it'll match what we have in std::io::Read
.
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.
Hum sure.
src/libstd/sys/unix/ext/fs.rs
Outdated
/// short read. | ||
/// | ||
/// [`File::read`]: ../../../../std/fs/struct.File.html#read.v |
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.
Why did you use read.v
instead of method.read
? I know they go to the same spot but i'm more used to reading the method.
style link anchors. (Same for write
farther down.)
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.
It's not targetting the same thing actually. :)
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.
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.
Hum, good point.
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 with @QuietMisdreavus's and @ollie27's comments addressed
src/libstd/sys/unix/ext/fs.rs
Outdated
/// let buf = &mut [0u8; 8]; | ||
/// let file = File::open("foo.txt")?; | ||
/// | ||
/// // We now read 8 bytes from the offset 10. |
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.
maybe something like this?
// Read up to 8 bytes from the offset 10.
let num_bytes_read = file.read_at(buf, 10)?;
println!("read {} bytes: {:?}", num_bytes_read, buf);
8892230
to
062705d
Compare
/// let mut buf = [0u8; 8]; | ||
/// let file = File::open("foo.txt")?; | ||
/// | ||
/// // We now read 8 bytes from the offset 10. |
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.
this is not guaranteed to read 8 bytes, so phrasing it as 'up to 8 bytes' is a bit more accurate
062705d
to
7035a25
Compare
☔ The latest upstream changes (presumably #45862) made this pull request unmergeable. Please resolve the merge conflicts. |
r=me with merge conflicts addressed |
7035a25
to
c09adc4
Compare
@bors: r=frewsxcv rollup |
📌 Commit c09adc4 has been approved by |
…wsxcv Add missing links and examples for FileExt r? @rust-lang/docs
r? @rust-lang/docs