Get rid of SliceBuf

This commit is contained in:
Carl Lerche
2016-08-05 22:49:41 -07:00
parent 16b4266c3c
commit b2efe63c70
3 changed files with 6 additions and 67 deletions
+6 -6
View File
@@ -2,14 +2,12 @@ mod append;
mod byte;
mod ring;
mod sink;
mod slice;
mod source;
mod take;
pub use self::append::AppendBuf;
pub use self::byte::{ByteBuf, MutByteBuf, ROByteBuf};
pub use self::ring::RingBuf;
pub use self::slice::{SliceBuf, MutSliceBuf};
pub use self::take::Take;
use {ByteStr, RopeBuf};
@@ -43,9 +41,10 @@ pub trait Buf {
/// Returns the number of bytes read.
///
/// ```
/// use bytes::{SliceBuf, Buf};
/// use std::io::Cursor;
/// use bytes::Buf;
///
/// let mut buf = SliceBuf::wrap(b"hello world");
/// let mut buf = Cursor::new(b"hello world");
/// let mut dst = [0; 5];
///
/// buf.read_slice(&mut dst);
@@ -117,12 +116,13 @@ pub trait MutBuf : Sized {
/// Returns the number of bytes written.
///
/// ```
/// use bytes::{MutSliceBuf, Buf, MutBuf};
/// use bytes::MutBuf;
/// use std::io::Cursor;
///
/// let mut dst = [0; 6];
///
/// {
/// let mut buf = MutSliceBuf::wrap(&mut dst);
/// let mut buf = Cursor::new(&mut dst);
/// buf.write_slice(b"hello");
///
/// assert_eq!(1, buf.remaining());
-59
View File
@@ -1,59 +0,0 @@
use std::cmp;
use {Buf, MutBuf};
// TODO: Rename -> Cursor. Use as buf for various byte strings
pub struct SliceBuf<'a> {
bytes: &'a [u8],
pos: usize
}
impl<'a> SliceBuf<'a> {
pub fn wrap(bytes: &'a [u8]) -> SliceBuf<'a> {
SliceBuf { bytes: bytes, pos: 0 }
}
}
impl<'a> Buf for SliceBuf<'a> {
fn remaining(&self) -> usize {
self.bytes.len() - self.pos
}
fn bytes<'b>(&'b self) -> &'b [u8] {
&self.bytes[self.pos..]
}
fn advance(&mut self, mut cnt: usize) {
cnt = cmp::min(cnt, self.remaining());
self.pos += cnt;
}
}
pub struct MutSliceBuf<'a> {
bytes: &'a mut [u8],
pos: usize
}
impl<'a> MutSliceBuf<'a> {
pub fn wrap(bytes: &'a mut [u8]) -> MutSliceBuf<'a> {
MutSliceBuf {
bytes: bytes,
pos: 0
}
}
}
impl<'a> MutBuf for MutSliceBuf<'a> {
fn remaining(&self) -> usize {
self.bytes.len() - self.pos
}
unsafe fn advance(&mut self, mut cnt: usize) {
cnt = cmp::min(cnt, self.remaining());
self.pos += cnt;
}
unsafe fn mut_bytes<'b>(&'b mut self) -> &'b mut [u8] {
&mut self.bytes[self.pos..]
}
}
-2
View File
@@ -14,8 +14,6 @@ pub use buf::{
MutByteBuf,
RingBuf,
ROByteBuf,
SliceBuf,
MutSliceBuf,
Take,
ReadExt,
WriteExt,