macro_rules! str_array {
(@impl item
($([$attr:meta])*)
($($item_kind:tt)*)
$name:ident = $val:expr; $($rest:tt)*
) => { ... };
($(#[$attr:meta])* static mut $($rest:tt)*) => { ... };
($(#[$attr:meta])* static $($rest:tt)*) => { ... };
($(#[$attr:meta])* const $($rest:tt)*) => { ... };
($val:expr) => { ... };
() => { ... };
}Expand description
Builds StrArray from constant &str.
ยงExamples
Pass a const expression of &str to build a StrArray with the same length.
let x = str_array!("Buzz");
assert_eq!(x.len(), 4);
const NAME: &str = "Sally";
let y = str_array!(NAME);
assert_eq!(y, "Sally");Define static or const items by eliding the type.
The length of the StrArray uses the length of the assigned string.
Note that the assignment expression currently is evaluated twice,
but this should have no effect due to it being in const.
str_array! {
static STATIC = "static";
static mut STATIC_MUT = "static_mut";
const CONST = "constant";
}
assert_eq!(STATIC, "static");
assert_eq!(unsafe { &*addr_of!(STATIC_MUT) }, "static_mut");
assert_eq!(CONST, "constant");