8 releases (5 breaking)

0.13.0 Feb 12, 2025
0.12.2 Dec 6, 2024
0.12.1 Nov 11, 2024
0.12.0 Mar 10, 2021
0.7.0 Sep 17, 2018

#378 in Rust patterns

Download history 2760/week @ 2024-11-18 2296/week @ 2024-11-25 2657/week @ 2024-12-02 2253/week @ 2024-12-09 2137/week @ 2024-12-16 1148/week @ 2024-12-23 1464/week @ 2024-12-30 2335/week @ 2025-01-06 2749/week @ 2025-01-13 2470/week @ 2025-01-20 2505/week @ 2025-01-27 4922/week @ 2025-02-03 3871/week @ 2025-02-10 2412/week @ 2025-02-17 3879/week @ 2025-02-24 2533/week @ 2025-03-03

13,042 downloads per month
Used in 14 crates (2 directly)

MIT license

11KB
106 lines

A simplified implementation of the bytes crate, with different features, less safety.

The crate is currently minimalist rather than maximalist, and for example does not support methods on BytesMut that seem like they should be safe, because they are not yet needed. For example, BytesMut should be able to implement Send, and BytesMut::extract_to could return a BytesMut rather than a Bytes.

Examples

use timely_bytes::arc::BytesMut;

let bytes = vec![0u8; 1024];
let mut shared1 = BytesMut::from(bytes);
let mut shared2 = shared1.extract_to(100);
let mut shared3 = shared1.extract_to(100);
let mut shared4 = shared2.extract_to(60);

assert_eq!(shared1.len(), 824);
assert_eq!(shared2.len(), 40);
assert_eq!(shared3.len(), 100);
assert_eq!(shared4.len(), 60);

for byte in shared1.iter_mut() { *byte = 1u8; }

// memory in slabs [4, 2, 3, 1]: merge back in arbitrary order.
shared2.try_merge(shared3).ok().expect("Failed to merge 2 and 3");
shared2.try_merge(shared1.freeze()).ok().expect("Failed to merge 23 and 1");
shared4.try_merge(shared2).ok().expect("Failed to merge 4 and 231");

assert_eq!(shared4.len(), 1024);

No runtime deps