Macro abi_stable::nulstr_trunc

source ·
macro_rules! nulstr_trunc {
    ($str:expr $(,)*) => { ... };
}
Expand description

Constructs a NulStr from a string literal, truncating the string on internal nul bytes.

§Correctness

This truncates the passed in string if it contains nul bytes, which means that silent truncation can happen with arbitrary inputs, rather than compile-time errors.

§Example

use abi_stable::nulstr_trunc;

assert_eq!(nulstr_trunc!("Huh?").to_str_with_nul(), "Huh?\0");

assert_eq!(nulstr_trunc!("Hello!").to_str_with_nul(), "Hello!\0");

assert_eq!(
    nulstr_trunc!("Hello\0, world!").to_str_with_nul(),
    "Hello\0"
);