diff options
Diffstat (limited to 'src/buf/take.rs')
-rw-r--r-- | src/buf/take.rs | 12 |
1 files changed, 10 insertions, 2 deletions
diff --git a/src/buf/take.rs b/src/buf/take.rs index 1747f6e..d3cb10a 100644 --- a/src/buf/take.rs +++ b/src/buf/take.rs @@ -1,11 +1,11 @@ -use crate::Buf; +use crate::{Buf, Bytes}; use core::cmp; /// A `Buf` adapter which limits the bytes read from an underlying buffer. /// /// This struct is generally created by calling `take()` on `Buf`. See -/// documentation of [`take()`](trait.BufExt.html#method.take) for more details. +/// documentation of [`take()`](trait.Buf.html#method.take) for more details. #[derive(Debug)] pub struct Take<T> { inner: T, @@ -144,4 +144,12 @@ impl<T: Buf> Buf for Take<T> { self.inner.advance(cnt); self.limit -= cnt; } + + fn copy_to_bytes(&mut self, len: usize) -> Bytes { + assert!(len <= self.remaining(), "`len` greater than remaining"); + + let r = self.inner.copy_to_bytes(len); + self.limit -= len; + r + } } |