Add take fn to Buf & MutBuf

This commit is contained in:
Carl Lerche
2016-09-21 20:41:21 -07:00
parent 4105901244
commit 3c58b0c75c
+11 -1
View File
@@ -4,7 +4,7 @@ pub mod byte;
pub mod ring;
pub mod take;
use {Bytes};
use {Bytes, Take};
use byteorder::ByteOrder;
use std::{cmp, fmt, io, ptr, usize};
@@ -165,6 +165,11 @@ pub trait Buf {
self.read_slice(&mut buf);
T::read_f64(&buf)
}
/// Create an adapter which will limit at most `limit` bytes from it.
fn take(self, limit: usize) -> Take<Self> where Self: Sized {
Take::new(self, limit)
}
}
/// A trait for values that provide sequential write access to bytes.
@@ -329,6 +334,11 @@ pub trait MutBuf {
T::write_f64(&mut buf, n);
self.write_slice(&buf)
}
/// Create an adapter which will limit at most `limit` bytes from it.
fn take(self, limit: usize) -> Take<Self> where Self: Sized {
Take::new(self, limit)
}
}
/*