-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
Improve documentation for std::io::Cursor #27163
Conversation
/// over `T` itself. Instead, specific implementations are provided for various | ||
/// in-memory buffer types like `Vec<u8>` and `&[u8]`. | ||
/// Cursors are typically used with in-memory buffers to allow them to | ||
/// implement `Read` and/or `Write`, allowing these buffers to but used |
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.
s/but/be/
acbfd77
to
421f45e
Compare
/// implementation. | ||
/// A `Cursor` wraps another type and provides it with a [`Seek`][seek] | ||
/// implementation. This is often done to allow I/O operations on a non-I/O | ||
/// type. |
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 may want to be rephrased a bit because the primitive types (Vec<u8>
, &[u8]
, etc) already implement I/O traits. The main functionality added by Cursor
is the ability to seek.
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 thought they implemented them because they implemented Cursor, though.
421f45e
to
6f8ec11
Compare
@alexcrichton updated! |
/// use std::net::TcpStream; | ||
/// | ||
/// // a library function we've written | ||
/// fn write_ten_bytes_at_end<W: Write>(writer: &mut W) -> io::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.
This will need a Seek
bound to compile, and you may want to switch to a File
instead of a TcpStream
(as you can't seek network streams)
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.
so, the problem with File is that it already implements Seek directly...
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.
yeah, i'm thinking this just needs to change wholesale. any idea of a good alternate example?
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.
Oh I think this is a fine example, the function is just generic over Write + Seek
and normally you instantiate it with File
but in tests you use Cursor<Vec<u8>>
kicking this out of the rollup for now |
oh wait it's not in it. yay first thing in the morning |
6f8ec11
to
103749d
Compare
Beef up the docs on the type, as well as adding examples for all methods.
Okay, updated with a |
…lexcrichton Beef up the docs on the type, as well as adding examples for all methods. r? @alexcrichton
Beef up the docs on the type, as well as adding examples for all
methods.
r? @alexcrichton