Function sp_runtime::str_array

source ·
pub const fn str_array<const N: usize>(s: &str) -> [u8; N]
Expand description

Utility function to declare string literals backed by an array of length N.

The input can be shorter than N, in that case the end of the array is padded with zeros.

str_array is useful when converting strings that end up in the storage as fixed size arrays or in const contexts where static data types have strings that could also end up in the storage.

§Example

const MY_STR: [u8; 6] = str_array("data");
assert_eq!(MY_STR, *b"data\0\0");