append-only-bytes

Crates.ioappend-only-bytes
lib.rsappend-only-bytes
version0.1.12
sourcesrc
created_at2022-12-06 03:45:14.901732
updated_at2023-10-28 05:34:22.17669
descriptionShareable append-only bytes
homepagehttps://github.com/zxch3n/append-only-bytes
repositoryhttps://github.com/zxch3n/append-only-bytes
max_upload_size
id730826
size19,371
Zixuan Chen (zxch3n)

documentation

https://docs.rs/append-only-bytes

README

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
Commit count: 26

cargo fmt