Add read_byte and write_byte

This commit is contained in:
Carl Lerche
2015-02-10 19:29:39 -08:00
parent 053b97a6e7
commit 974043bd13
+23 -1
View File
@@ -47,7 +47,7 @@ pub trait Buf {
self.remaining() > 0
}
/// Read bytes from this Buf into the given slice and advance the cursor by
/// Read bytes from the `Buf` into the given slice and advance the cursor by
/// the number of bytes read.
///
/// If there are fewer bytes remaining than is needed to satisfy the
@@ -86,6 +86,17 @@ pub trait Buf {
len
}
/// Read a single byte from the `Buf`
fn read_byte(&mut self) -> Option<u8> {
let mut dst = [0];
if self.read_slice(&mut dst) == 0 {
return None;
}
Some(dst[0])
}
}
pub trait BufExt {
@@ -156,6 +167,17 @@ pub trait MutBuf : Sized {
len
}
/// Write a single byte to the `MuBuf`
fn write_byte(&mut self, byte: u8) -> bool {
let src = [byte];
if self.write_slice(&src) == 0 {
return false;
}
true
}
}
pub trait MutBufExt {