pub const fn to_bytes(this: &CStr) -> &[u8]
Expand description
Converts this CStr to a byte slice, excluding the nul terminator.
Const equivalent of CStr::to_bytes
§Performance
This function takes linear time to run, proportional to the length of this
.
§Const stabilization
The equivalent std function was const-stabilized in Rust 1.72.0.
§Example
use konst::{ffi::cstr, unwrap_ctx};
use std::ffi::CStr;
const CS: &CStr = unwrap_ctx!(cstr::from_bytes_with_nul(b"hmm...\0"));
const BYTES: &[u8] = cstr::to_bytes(CS);
assert_eq!(BYTES, b"hmm...");