13 releases

0.1.12 Oct 28, 2023
0.1.11 Sep 7, 2023
0.1.9 Aug 4, 2023
0.1.8 Jul 11, 2023
0.1.5 Dec 7, 2022

#1202 in Encoding

Download history 48/week @ 2024-07-22 98/week @ 2024-07-29 130/week @ 2024-08-05 187/week @ 2024-08-12 258/week @ 2024-08-19 58/week @ 2024-08-26 342/week @ 2024-09-02 254/week @ 2024-09-09 192/week @ 2024-09-16 110/week @ 2024-09-23 127/week @ 2024-09-30 87/week @ 2024-10-07 144/week @ 2024-10-14 41/week @ 2024-10-21 121/week @ 2024-10-28 103/week @ 2024-11-04

426 downloads per month
Used in 7 crates (3 directly)

MIT license

20KB
491 lines

append-only-bytes

Documentation

If an array is append-only and guarantees that all the existing data is immutable, we can safely share slices of this array across threads, while the owner can still safely append new data to it.

This is safe because no mutable byte has more than one owner. If there isn't enough capacity for a new append, AppendOnlyBytes will not deallocate the old memory if a ByteSlice is referring to it. The old memory will be deallocated only when all the ByteSlices referring to it are dropped.

Example

use append_only_bytes::{AppendOnlyBytes, BytesSlice};
let mut bytes = AppendOnlyBytes::new();
bytes.push_slice(&[1, 2, 3]);
let slice: BytesSlice = bytes.slice(1..);
bytes.push_slice(&[4, 5, 6]);
assert_eq!(&*slice, &[2, 3]);
assert_eq!(bytes.as_bytes(), &[1, 2, 3, 4, 5, 6])

Features

  • serde: support serde serialization and deserialization
  • u32_range: support u32 range for ByteSlices method

Dependencies

~160KB