rust/library/std/src/io
bors cf04ae54e6 Auto merge of #79705 - ijackson:bufwriter-disassemble, r=m-ou-se
BufWriter: Provide into_raw_parts

If something goes wrong, one might want to unpeel the layers of nested
Writers to perform recovery actions on the underlying writer, or reuse
its resources.

`into_inner` can be used for this when the inner writer is still
working.  But when the inner writer is broken, and returning errors,
`into_inner` simply gives you the error from flush, and the same
`Bufwriter` back again.

Here I provide the necessary function, which I have chosen to call
`into_raw_parts`.

I had to do something with `panicked`.  Returning it to the caller as
a boolean seemed rather bare.  Throwing the buffered data away in this
situation also seems unfriendly: maybe the programmer knows something
about the underlying writer and can recover somehow.

So I went for a custom Error.  This may be overkill, but it does have
the nice property that a caller who actually wants to look at the
buffered data, rather than simply extracting the inner writer, will be
told by the type system if they forget to handle the panicked case.

If a caller doesn't need the buffer, it can just be discarded.  That
WriterPanicked is a newtype around Vec<u8> means that hopefully the
layouts of the Ok and Err variants can be very similar, with just a
boolean discriminant.  So this custom error type should compile down
to nearly no code.

*If this general idea is felt appropriate, I will open a tracking issue, etc.*
2021-01-19 16:42:19 +00:00
..
buffered Auto merge of #79705 - ijackson:bufwriter-disassemble, r=m-ou-se 2021-01-19 16:42:19 +00:00
cursor Make some std::io functions const 2020-11-06 17:48:26 +01:00
error std: move "mod tests/benches" to separate files 2020-08-31 02:56:59 +00:00
impls std: move "mod tests/benches" to separate files 2020-08-31 02:56:59 +00:00
stdio std: move "mod tests/benches" to separate files 2020-08-31 02:56:59 +00:00
util Make some std::io functions const 2020-11-06 17:48:26 +01:00
copy.rs limit visibility of copy offload helpers to sys::unix module 2020-11-13 22:38:27 +01:00
cursor.rs Add tracking issue 2020-11-06 18:04:52 +01:00
error.rs std: move "mod tests/benches" to separate files 2020-08-31 02:56:59 +00:00
impls.rs std: impl of Write for &mut [u8]: document the buffer full error 2020-12-04 18:38:44 +00:00
mod.rs Add benchmark and fast path for BufReader::read_exact 2021-01-17 12:10:39 +10:00
prelude.rs mv std libs to library/ 2020-07-27 19:51:13 -05:00
stdio.rs Use Pin for the 'don't move' requirement of ReentrantMutex. 2020-12-08 22:57:57 +01:00
tests.rs move copy specialization tests to their own module 2020-11-13 22:38:27 +01:00
util.rs Auto merge of #75272 - the8472:spec-copy, r=KodrAus 2020-11-14 12:01:55 +00:00