chore: replace Vec::write_all usage with Vec::extend_from_slice

The underlying implementation simply calls extends_from_slice anyway,
but this removes the error that would never happen
https://doc.rust-lang.org/1.45.2/src/std/io/impls.rs.html#389-393
This commit is contained in:
Paolo Barbolini
2020-08-04 10:09:25 +02:00
parent 8fa66c1e0f
commit 4b238829c7

View File

@@ -45,9 +45,9 @@ impl ClientCodec {
match frame.len() {
0 => {
match self.escape_count {
0 => buf.write_all(b"\r\n.\r\n")?,
1 => buf.write_all(b"\n.\r\n")?,
2 => buf.write_all(b".\r\n")?,
0 => buf.extend_from_slice(b"\r\n.\r\n"),
1 => buf.extend_from_slice(b"\n.\r\n"),
2 => buf.extend_from_slice(b".\r\n"),
_ => unreachable!(),
}
self.escape_count = 0;
@@ -64,12 +64,12 @@ impl ClientCodec {
}
if self.escape_count == 3 {
self.escape_count = 0;
buf.write_all(&frame[start..idx])?;
buf.write_all(b".")?;
buf.extend_from_slice(&frame[start..idx]);
buf.extend_from_slice(b".");
start = idx;
}
}
buf.write_all(&frame[start..])?;
buf.extend_from_slice(&frame[start..]);
Ok(())
}
}