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

std: Implement io traits for io::Cursor of Vec references #25118

Closed
wants to merge 1 commit into from

Conversation

Projects
None yet
5 participants
@ruuda
Copy link
Contributor

ruuda commented May 5, 2015

For example, io::Cursor<&Vec<u8>> did not implement io::Read, whereas io::Cursor<Vec<u8>> did. There might be a good reason for this that I missed, but it is not impossible as this PR demonstrates.

Constructing a cursor from a reference is useful when you already have the vector. You can temporarily wrap it in a cursor to read from it or write to it, and continue using the vector when the cursor goes out of scope. There is no need to call into_inner.

I don’t know what the procedure is for stability attributes, so I did not add them yet.

r? @aturon

@bluss

This comment has been minimized.

Copy link
Contributor

bluss commented May 5, 2015

You could use Cursor<&[u8]> and similar, right? &Vec<T> is almost always replaceable with &[T]

@ruuda

This comment has been minimized.

Copy link
Contributor Author

ruuda commented May 5, 2015

For reading, yes, but for writing, no, because &mut [u8] cannot grow, and &mut Vec<u8> can.

@bluss

This comment has been minimized.

Copy link
Contributor

bluss commented May 5, 2015

Ah but &mut Vec doesn't need a cursor (its length is the cursor).

@ruuda

This comment has been minimized.

Copy link
Contributor Author

ruuda commented May 5, 2015

It does if you want it to be Seek + Write.

@alexcrichton

This comment has been minimized.

Copy link
Member

alexcrichton commented May 5, 2015

Due to the way stability of trait implementations works, we'd be forced to mark all these with #[stable(feature = "...", since = "1.1.0")] (in terms of stability attributes), and I agree with @bluss that &Vec<u8> is probably too similar to &[u8] to add for now.

@alexcrichton alexcrichton added the T-libs label May 26, 2015

@Gankro

This comment has been minimized.

Copy link
Contributor

Gankro commented May 31, 2015

@alexcrichton Should this be closed?

Edit: It occurs to me that doing lazy-sunday triage when we're doing hardcore triage tomorrow is kinda pointless.

@alexcrichton

This comment has been minimized.

Copy link
Member

alexcrichton commented Jun 1, 2015

@Gankro ah yes this has gone a little stale, so I think I'll close this for now. We can always continue to explore these options in the future though!

@ruuda ruuda deleted the ruuda:cursor branch Nov 30, 2016

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.