StringTape
A memory-efficient string storage library compatible with Apache Arrow's string array format.
Stores multiple strings in a contiguous memory layout using offset-based indexing, similar to Arrow's String
and LargeString
arrays.
- Apache Arrow Compatible: Similar to
String
andLargeString
classes - Memory Efficient: All strings stored in a single contiguous buffer
no_std
Support: Can be used in embedded environments- Zero Dependencies: Pure Rust implementation
Quick Start
use ;
// Create a new StringTape with 32-bit offsets
let mut tape = new;
tape.push?;
tape.push?;
assert_eq!;
assert_eq!;
assert_eq!;
// Iterate over strings
for s in &tape
// Build from iterator
let tape2: StringTape32 = .into_iter.collect;
assert_eq!;
# Ok::
Memory Layout
StringTape uses the same memory layout as Apache Arrow string arrays:
Data buffer: [h,e,l,l,o,w,o,r,l,d]
Offset buffer: [0, 5, 10]
API Overview
Creation
// Empty tape
let tape = new;
// Pre-allocated capacity
let tape = with_capacity?; // 1KB data, 100 strings
// Custom allocator
let allocator = DefaultAllocator;
let tape = new_in;
let tape = with_capacity_in?;
// From iterator
let tape: StringTape32 = .into_iter.collect;
Adding Strings
let mut tape = new;
// Single string
tape.push?;
// Multiple strings
tape.extend?;
Accessing Strings
// By index (panics if out of bounds)
let s = &tape;
// Safe access
let s = tape.get; // Returns Option<&str>
// Iteration
for s in &tape
// Collect to Vec
let strings: = tape.iter.collect;
Capacity Management
let mut tape = new;
// Check sizes
println!;
println!;
println!;
// Reserve space
tape.reserve?; // 1KB data, 100 strings
// Clear contents
tape.clear;
// Truncate
tape.truncate; // Keep first 5 strings
Apache Arrow Interop
These APIs can be used to construct Arrow arrays without copying the data:
let mut tape = new;
tape.push?;
tape.push?;
let = tape.as_raw_parts;
no_std
Support
StringTape can be used in no_std
environments:
[]
= { = "0.1", = false }
In no_std
mode:
- Requires
alloc
for dynamic allocation - All functionality is preserved
- Error types implement
Display
but notstd::error::Error
Testing
Run tests for both std
and no_std
configurations: