diff --git a/CHANGELOG.md b/CHANGELOG.md index 1e52492..e1bb918 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -36,6 +36,7 @@ - implemented `Stream` directly for `Bytes` with a safe `iter_offsets` iterator - added `pop_back` and `pop_front` helpers and rewrote parser examples - added tests covering `pop_front` and `pop_back` +- added tests covering `take_prefix` and `take_suffix` - removed the Completed Work section from `INVENTORY.md` and documented its use - added `Bytes::try_unwrap_owner` to reclaim the owner when uniquely held - simplified `Bytes::try_unwrap_owner` implementation diff --git a/INVENTORY.md b/INVENTORY.md index d786b60..8cde943 100644 --- a/INVENTORY.md +++ b/INVENTORY.md @@ -5,6 +5,7 @@ ## Desired Functionality - Add Kani proofs for winnow view helpers. +- Implement `ExactSizeIterator` or `FusedIterator` for `BytesIterOffsets` to simplify iteration. ## Discovered Issues - None at the moment. diff --git a/src/tests.rs b/src/tests.rs index 238d50e..8cb3d74 100644 --- a/src/tests.rs +++ b/src/tests.rs @@ -174,6 +174,24 @@ fn test_pop_back() { assert_eq!(bytes.pop_back(), None); } +#[test] +fn test_take_prefix() { + let mut bytes = Bytes::from(b"abcdef".to_vec()); + let prefix = bytes.take_prefix(2).expect("prefix"); + assert_eq!(prefix.as_ref(), b"ab"); + assert_eq!(bytes.as_ref(), b"cdef"); + assert!(bytes.take_prefix(10).is_none()); +} + +#[test] +fn test_take_suffix() { + let mut bytes = Bytes::from(b"abcdef".to_vec()); + let suffix = bytes.take_suffix(2).expect("suffix"); + assert_eq!(suffix.as_ref(), b"ef"); + assert_eq!(bytes.as_ref(), b"abcd"); + assert!(bytes.take_suffix(10).is_none()); +} + #[test] fn test_weakbytes_multiple_upgrades() { let bytes = Bytes::from(b"hello".to_vec());