Expand description
Helper crate to concat static strings during compilation.
Strings (&'static str) that are known during compile-time can’t
currently easily concatenated nor joined with a seperator. This
tiny crate aims to help with the situation by providing conviencne
macros that execute the required steps.
Some of the limitations that have to be worked around are:
- No const iterators, yet.
- Allocating static memory must be done with a fixed and know size.
- Writing into strings must be done “manually” bytewise as there is no copy implementation.
- Byteslices aren’t available in const-context requiring manually indexing into the buffers.
All of those aren’t show-stoppers but don’t exactly enable idiomatic Rust code and require walking the thin line of whats possible and what isn’t.
Example usage:
use const_str_join::declare_joined_str;
const A: &'static str = "A";
const B: &'static str = "B";
const C: &'static str = "C";
const ALL: [&'static str; 3] = [A, B, C] ;
// declare a new &'static str with the final string
declare_joined_str!(ALL_JOINED, ALL, ",");
assert_eq!(ALL_JOINED, "A,B,C");Macros§
- declare_
joined_ str - Declares a new constant value
namewith the joined string ofarrayandsep. Example usage: - joined_
array - Returns a buffer (
[u8; N]) that contains the joined string as bytes.