-
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
Implement Read/Write on Cursor over &mut Vec #30132
Labels
C-feature-accepted
Category: A feature request that has been accepted pending implementation.
T-libs-api
Relevant to the library API team, which will review and decide on the PR/issue.
Comments
Good workaround is to call the |
AFAICT, adding such an impl is a breaking change: use std::marker::PhantomData;
struct Cursor<T>(PhantomData<T>);
impl<T> Cursor<T> {
fn new(_: T) -> Self {
Cursor(PhantomData)
}
}
trait Write {
fn flush(&mut self) {}
}
impl<'a> Write for Cursor<&'a mut [u8]> {}
impl Write for Cursor<Vec<u8>> {}
// This code doesn't type check if this is uncommented:
// impl<'a> Write for Cursor<&'a mut Vec<u8>> {}
fn main() {
let mut vec = vec![0u8];
Cursor::new(vec.as_mut()).flush();
} |
New implementations are allowed to cause inference breakage. |
steveklabnik
added
T-libs-api
Relevant to the library API team, which will review and decide on the PR/issue.
and removed
A-libs
labels
Mar 24, 2017
Mark-Simulacrum
added
the
C-feature-request
Category: A feature request, i.e: not implemented / a PR.
label
Jul 24, 2017
dtolnay
added
C-feature-accepted
Category: A feature request that has been accepted pending implementation.
and removed
C-feature-request
Category: A feature request, i.e: not implemented / a PR.
labels
Nov 18, 2017
Seems reasonable. I would be interested in seeing a PR that implements this. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
C-feature-accepted
Category: A feature request that has been accepted pending implementation.
T-libs-api
Relevant to the library API team, which will review and decide on the PR/issue.
It is currently impossible to use a std::io::Cursor over a Vec in a smart pointer (Mutex, RefCell, ...) in a sane way. Please implement Read/Write/... over Cursor<&'a mut Vec>.
Discussed on users.rust-lang.org.
The text was updated successfully, but these errors were encountered: