-
Notifications
You must be signed in to change notification settings - Fork 13.2k
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # 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. |
Seems reasonable. I would be interested in seeing a PR that implements this. |
# for free
to join this conversation on GitHub.
Already have an account?
# 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: