Add must_use to split, split_off, and split_to

This commit is contained in:
Sean McArthur
2019-12-04 12:39:48 -08:00
parent af606aab9b
commit a4908213a6
3 changed files with 70 additions and 11 deletions
+24
View File
@@ -288,6 +288,7 @@ impl Bytes {
/// # Panics
///
/// Panics if `at > len`.
#[must_use = "consider Bytes::truncate if you don't need the other half"]
pub fn split_off(&mut self, at: usize) -> Bytes {
assert!(at <= self.len());
@@ -331,6 +332,7 @@ impl Bytes {
/// # Panics
///
/// Panics if `at > len`.
#[must_use = "consider Bytes::advance if you don't need the other half"]
pub fn split_to(&mut self, at: usize) -> Bytes {
assert!(at <= self.len());
@@ -913,6 +915,28 @@ unsafe fn release_shared(ptr: *mut Shared) {
Box::from_raw(ptr);
}
// compile-fails
/// ```compile_fail
/// use bytes::Bytes;
/// #[deny(unused_must_use)]
/// {
/// let mut b1 = Bytes::from("hello world");
/// b1.split_to(6);
/// }
/// ```
fn _split_to_must_use() {}
/// ```compile_fail
/// use bytes::Bytes;
/// #[deny(unused_must_use)]
/// {
/// let mut b1 = Bytes::from("hello world");
/// b1.split_off(6);
/// }
/// ```
fn _split_off_must_use() {}
// fuzz tests
#[cfg(all(test, loom))]
mod fuzz {