diff options
author | 2019-06-28 14:53:42 +0200 | |
---|---|---|
committer | 2019-06-28 14:53:42 +0200 | |
commit | a3cd1707ee4e967964d6a682741ed391dd16318f (patch) | |
tree | ad54c9b9e9c1a8e812cb4d037d4d4dd1139fbd7e | |
parent | 3f4a7b6c868e7f79069c9b182dd74d0f3dc57b93 (diff) | |
parent | 0b80624939da8f53466078de1ae320f120e34a35 (diff) | |
download | circular-a3cd1707ee4e967964d6a682741ed391dd16318f.tar.gz circular-a3cd1707ee4e967964d6a682741ed391dd16318f.tar.bz2 circular-a3cd1707ee4e967964d6a682741ed391dd16318f.zip |
Merge pull request #3 from chifflier/consume-noshift01
Add consume_noshift (consume data without moving it)
-rw-r--r-- | src/lib.rs | 18 |
1 files changed, 18 insertions, 0 deletions
@@ -140,6 +140,16 @@ impl Buffer { cnt } + /// advances the position tracker + /// + /// This method is similar to `consume()` but will not move data + /// to the beginning of the buffer + pub fn consume_noshift(&mut self, count: usize) -> usize { + let cnt = cmp::min(count, self.available_data()); + self.position += cnt; + cnt + } + /// after having written data to the buffer, use this function /// to indicate how many bytes were written /// @@ -394,4 +404,12 @@ mod tests { assert_eq!(b.available_data(), 3); println!("{:?}", b.position()); } + + #[test] + fn consume_without_shift() { + let mut b = Buffer::with_capacity(10); + let _ = b.write(&b"abcdefgh"[..]); + b.consume_noshift(6); + assert_eq!(b.position(), 6); + } } |