Implement IntoBuf for mut slices. (#214)

With this if foo is a mutable slice, it is possible to do

foo.into_buf().put_u32_le(42);

Before this patch into_buf would create a Cursor<&'a [u8]> and it
would not be possible to write into it.
This commit is contained in:
Rafael Ávila de Espíndola
2018-07-12 20:16:08 -07:00
committed by Carl Lerche
parent 042aa9023b
commit 052648c3f5
2 changed files with 16 additions and 1 deletions
+8
View File
@@ -63,6 +63,14 @@ impl<'a> IntoBuf for &'a [u8] {
}
}
impl<'a> IntoBuf for &'a mut [u8] {
type Buf = io::Cursor<&'a mut [u8]>;
fn into_buf(self) -> Self::Buf {
io::Cursor::new(self)
}
}
impl<'a> IntoBuf for &'a str {
type Buf = io::Cursor<&'a [u8]>;