Function konst::ffi::cstr::from_bytes_with_nul

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

Converts a nul-terminated byte slice into a &CStr. Const equivalent of CStr::from_bytes_with_nul

§Example

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

use std::ffi::CStr;


const CS: &CStr = unwrap_ctx!(cstr::from_bytes_with_nul(b"foo bar\0"));

assert_eq!(CS.to_str().unwrap(), "foo bar");