stack_cstr
stack_cstr is a high-performance Rust library for creating C-compatible strings (&CStr) efficiently.
It uses a stack buffer for short strings to avoid heap allocation, and automatically falls back to heap allocation for longer strings.
The resulting strings are safe to pass to FFI functions.
Features
- Stack buffer allocation for short strings (default 128 bytes)
- Automatic heap fallback for longer strings
- Supports
format_args!style formatting - Returns
CArrayString<128>for easy FFI usage - Simple macro interface:
cstr!() - Ergonomic and safe for passing to C APIs
Usage Example
use CStr;
use cstr;
// Create a C-compatible string
let s = cstr!;
assert_eq!;
unsafe