actix_web/helpers.rs
1use std::io;
2
3use bytes::BufMut;
4
5/// An `io::Write`r that only requires mutable reference and assumes that there is space available
6/// in the buffer for every write operation or that it can be extended implicitly (like
7/// `bytes::BytesMut`, for example).
8///
9/// This is slightly faster (~10%) than `bytes::buf::Writer` in such cases because it does not
10/// perform a remaining length check before writing.
11pub(crate) struct MutWriter<'a, B>(pub(crate) &'a mut B);
12
13impl<B> io::Write for MutWriter<'_, B>
14where
15 B: BufMut,
16{
17 fn write(&mut self, buf: &[u8]) -> io::Result<usize> {
18 self.0.put_slice(buf);
19 Ok(buf.len())
20 }
21
22 fn flush(&mut self) -> io::Result<()> {
23 Ok(())
24 }
25}