strbuilder 0.1.0

A high-performance StringBuilder for Rust designed to avoid memory reallocations using cache-aligned chunks.
Documentation
  • Coverage
  • 0%
    0 out of 5 items documented0 out of 0 items with examples
  • Size
  • Source code size: 23.01 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 403.97 kB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 37s Average build duration of successful builds.
  • all releases: 20s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • dadencukillia/strbuilder
    1 0 0
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • dadencukillia

🧱 strbuilder

StringBuilder for Rust without reallocations

📦 Installation

This project is published on crates.io. You can add it to your project by running:

cargo add strbuilder
# or
cargo add strbuilder --features safe

🌟 Key features

  • No Reallocations: Data never gets reallocated to a new, larger memory segment when the text grows. It simply links a new chunk onto the stack/heap
  • Cache-Line Alignment: Every text chunk (StringChunk) is forced to align tightly to 64-byte boundaries
  • Two sides: You can use unsafe but perfomant (the default) or safe but more slower variants of code by switching the safe feature

🚀 Usage Example

use strbuilder::StringBuilder;

let mut string_builder = StringBuilder::from("Hello,");
// or
let mut string_builder = StringBuilder::new();

string_builder.push_str(" ");
string_builder.push_str("world!");

let result = string_builder.to_string();
// or
println!("{:?}", string_builder);

⚙️ How it works

  • StringChunk: A backward-linked list under the hood, utilizing byte chunks that fit perfectly into a single CPU cache-line
  • StringBuilder: A lightweight controller containing a pointer to the last node of the linked list and the total byte count
[ first StringChunk (64B) ] <--- [ second StringChunk (64B) ] <--- [ third StringChunk (64B) ]
  |-- bytes: [u8; 56]              |-- bytes: [u8; 56]               |-- bytes: [u8; 56]
  |-- prev: null                   |-- prev: *const Chunk (first)    |-- prev: *const Chunk (second)

[ StringBuilder (12B) ]
  |-- bytes_count: usize
  |-- last_chunk: *mut StringChunk (third)