hipstr
Yet another string for Rust π¦
- no copy literal wrapping via
from_static(aconstconstructor) - no alloc small strings (23 bytes on 64-bit platform)
- no copy owned slices
- zero dependency
And bytes too!
β‘ Examples
use HipStr;
let simple_greetings = from_static;
let _clone = simple_greetings.clone; // no copy
let user = "John";
let greetings = from;
let _user = greetings.slice: // no copy
βοΈ Features
serde: provides serialization/deserialization support withserdecrateunstable: exposes internalBackendtrait that may change at any moment
β£οΈ Safety of hipstr
This crate uses unsafe extensively. π€·
It exploits the 1-bit alignment niche in pointers existing on most platforms (I think all Rustc supported platforms) to distinguish the inline representation from the other representations.
To make things safer, Rust is tested thoroughly on multiple platforms, normally and with Miri (the MIR interpreter).
π§ͺ Testing
β Coverage
This crate has near full line coverage:
# or
Check out the current coverage on Codecov:
π₯οΈ Cross-platform testing
You can easily run the test on various platforms with cross:
π Miri
This crate runs successfully with Miri:
MIRIFLAGS=-Zmiri-symbolic-alignment-check
for; do
MIRIFLAGS="-Zmiri-seed=" || { ; break; };
done
To check with different word size and endianness:
# Big endian, 64-bit
# Little endian, 32-bit
π¦ Similar crates
arcstr: no inline repr, heavy slice (with dedicated substring type) and customArc.flexstr: no slice, very similar but use anArc<str>instead of anArc<String>(remove one level of indirection but use fat pointers).imstr: no inline repr, otherwise very similar.- and many more.
In short, HipStr, one string type to rule them allβ¦
π TODOs
- More copy on write API (like
imstr)?
π Author and licenses
For now, just me PoLazarus π»
Help welcome! π¨
MIT + Apache
