Skip to content

std: add a Writer impl for &mut [u8] #19928

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

Closed
wants to merge 1 commit into from
Closed

Conversation

erickt
Copy link
Contributor

@erickt erickt commented Dec 16, 2014

@alexcrichton mentioned in the io reform rfc that there might be interest in reviving the Writer for &mut [u8], so I revived the PR for consideration. As written, it needs to do some unsafe magic in order to advance the mutable slice. It would be nice if this was someday factored out into a method on the slice itself.

@sfackler
Copy link
Member

Can you add a cfail test to make sure that let mut v = vec![]; write!(v, "hi"); doesn't compile?

@Gankra
Copy link
Contributor

Gankra commented Jan 2, 2015

@erickt status?

@nwin
Copy link
Contributor

nwin commented Jan 7, 2015

The unsafe part can actually be reduced to (the transmute is just there for the lifetime)

*self = unsafe { mem::transmute(self.slice_from_mut(write_len)) };

I still wonder why it is needed for the Writer but not for the Reader.

@huonw
Copy link
Member

huonw commented Jan 19, 2015

r? @aturon

@alexcrichton
Copy link
Member

Closing due to inactivity, but feel free to reopen once more of the I/O reform RFCs have landed!

lnicola pushed a commit to lnicola/rust that referenced this pull request Jun 9, 2025
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.

7 participants