diff --git a/src/buf/mod.rs b/src/buf/mod.rs index b5cd568..acc2888 100644 --- a/src/buf/mod.rs +++ b/src/buf/mod.rs @@ -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 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 where Self: Sized { + Take::new(self, limit) + } } /*