macro_rules! cformat {
($ ($ arg : tt) *) => { ... };
}Expand description
format! for C strings: builds the formatted String and converts it to a
CString in one visibly-named step.
This is the recommended way to build dynamic channel URIs and other C-string
arguments. The c-prefix keeps the heap allocation greppable and visible at the
call site — important for latency-sensitive code review — while removing the
format!(...).into_c_string() noise:
let port = 4040;
let uri = cformat!("aeron:udp?endpoint=localhost:{port}");
assert_eq!(uri.to_bytes(), b"aeron:udp?endpoint=localhost:4040");The three-tier pattern for C-string arguments (cheapest first):
c"aeron:ipc"literals — compile-time&'static CStr, zero runtime cost. Use for every constant channel/name.cformat!(...)— one heap allocation (the formattedString;CString::newreuses its buffer). Use for dynamic URIs built once per stream/reconnect.- Reuse — build the
CStringonce, store it, pass&iton every call (zero-copy via&CString → &CStrderef). Use for anything on a repeated path.
Panics if the formatted string contains an interior nul byte.