Skip to content
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

Merged
merged 1 commit into from
Jul 22, 2015

Conversation

steveklabnik
Copy link
Member

Beef up the docs on the type, as well as adding examples for all
methods.

r? @alexcrichton

/// 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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/but/be/

/// 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.
Copy link
Member

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.

Copy link
Member Author

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.

@steveklabnik
Copy link
Member Author

@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<()> {
Copy link
Member

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)

Copy link
Member Author

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...

Copy link
Member Author

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?

Copy link
Member

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>>

@steveklabnik
Copy link
Member Author

kicking this out of the rollup for now

@steveklabnik
Copy link
Member Author

oh wait it's not in it. yay first thing in the morning

Beef up the docs on the type, as well as adding examples for all
methods.
@steveklabnik
Copy link
Member Author

Okay, updated with a File example, what do you think now, @alexcrichton ?

@alexcrichton
Copy link
Member

@bors: r+ 103749d rollup

Looks good to me!

steveklabnik added a commit to steveklabnik/rust that referenced this pull request Jul 22, 2015
…lexcrichton

Beef up the docs on the type, as well as adding examples for all
methods.

r? @alexcrichton
@bors bors merged commit 103749d into rust-lang:master Jul 22, 2015
@steveklabnik steveklabnik deleted the doc_std_io_cursor branch June 19, 2016 20:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants