add Bytes::is_unique (#643)

This commit is contained in:
Cyborus04
2024-01-19 23:59:30 +01:00
committed by GitHub
parent abb4a2e66c
commit 0864aea970
3 changed files with 84 additions and 0 deletions
+33
View File
@@ -1208,3 +1208,36 @@ fn test_bytes_capacity_len() {
}
}
}
#[test]
fn static_is_unique() {
let b = Bytes::from_static(LONG);
assert!(!b.is_unique());
}
#[test]
fn vec_is_unique() {
let v: Vec<u8> = LONG.to_vec();
let b = Bytes::from(v);
assert!(b.is_unique());
}
#[test]
fn arc_is_unique() {
let v: Vec<u8> = LONG.to_vec();
let b = Bytes::from(v);
let c = b.clone();
assert!(!b.is_unique());
drop(c);
assert!(b.is_unique());
}
#[test]
fn shared_is_unique() {
let v: Vec<u8> = LONG.to_vec();
let b = Bytes::from(v);
let c = b.clone();
assert!(!c.is_unique());
drop(b);
assert!(c.is_unique());
}