2019-04-18 14:28:47 +02:00
|
|
|
use bytes::BytesMut;
|
2019-04-17 20:12:31 +02:00
|
|
|
|
|
|
|
/// An [`io::Write`] impl for [`BytesMut`].
|
|
|
|
///
|
|
|
|
/// In contrast to [`bytes::buf::Writer`] this [`io::Write] implementation
|
|
|
|
/// transparently reserves enough space for [`io::Write::write_all`] to
|
|
|
|
/// succeed, i.e. it does not require upfront reservation of space.
|
|
|
|
pub(crate) struct BytesWriter(pub(crate) BytesMut);
|
|
|
|
|
|
|
|
impl std::io::Write for BytesWriter {
|
|
|
|
fn write(&mut self, src: &[u8]) -> std::io::Result<usize> {
|
2019-04-18 14:28:47 +02:00
|
|
|
self.0.extend_from_slice(src);
|
|
|
|
Ok(src.len())
|
2019-04-17 20:12:31 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
fn flush(&mut self) -> std::io::Result<()> {
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|