Function konst::ffi::cstr::from_bytes_until_nul

source ·
pub const fn from_bytes_until_nul(
    bytes: &[u8],
) -> Result<&CStr, FromBytesUntilNulError>
Expand description

Converts a byte slice which contains any amount of nul bytes into a &CStr. Const equivalent of CStr::from_bytes_until_nul

§Example

use konst::{ffi::cstr, unwrap_ctx};

use std::ffi::CStr;


const CS: &CStr = unwrap_ctx!(cstr::from_bytes_until_nul(b"hello\0world"));

assert_eq!(CS.to_str().unwrap(), "hello");