cstr_array

Macro cstr_array 

Source
macro_rules! cstr_array {
    (@impl item
        ($([$attr:meta])*)
        ($($item_kind:tt)*)
        $name:ident: $strarray_ty:ty = $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 CStrArray from constant &CStr.

ยงExamples

Pass a const expression of &CStr to build a CStrArray with the same length.

let x = cstr_array!(c"Buzz");
assert_eq!(x.len(), 4);

const NAME: &CStr = c"Sally";
let y = cstr_array!(NAME);
assert_eq!(y, c"Sally");

Define static or const items, using _ for the string length. The length of the array 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.

cstr_array! {
    static STATIC: CStrArray<_> = c"static";
    static mut STATIC_MUT: CStrArray<_> = c"static_mut";
    const CONST: CStrArray<_> = c"constant";
}
assert_eq!(STATIC, c"static");
assert_eq!(unsafe { &*addr_of!(STATIC_MUT) }, c"static_mut");
assert_eq!(CONST, c"constant");