mirror of
https://github.com/tokio-rs/bytes.git
synced 2026-08-25 00:00:22 +02:00
Add read_byte and write_byte
This commit is contained in:
+23
-1
@@ -47,7 +47,7 @@ pub trait Buf {
|
|||||||
self.remaining() > 0
|
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.
|
/// the number of bytes read.
|
||||||
///
|
///
|
||||||
/// If there are fewer bytes remaining than is needed to satisfy the
|
/// If there are fewer bytes remaining than is needed to satisfy the
|
||||||
@@ -86,6 +86,17 @@ pub trait Buf {
|
|||||||
|
|
||||||
len
|
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 {
|
pub trait BufExt {
|
||||||
@@ -156,6 +167,17 @@ pub trait MutBuf : Sized {
|
|||||||
|
|
||||||
len
|
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 {
|
pub trait MutBufExt {
|
||||||
|
|||||||
Reference in New Issue
Block a user