[lib] null-terminated, a library of null-terminated arrays


#1

null-terminated defines a null-terminated array type Nul parametric over the element type. I find it particularly useful dealing with C FFI where such arrays are common.

It includes methods to create a Nul of a slice, checking the last element is indeed null.

A reference to a Nul is a thin pointer so it can be readily used with FFI.

Happy hacking :slight_smile:


#2

Regarding Nul<u8> I think std::ffi::CString should be the same?


#3

Nope, it’s owned and a fat pointer. Maybe you meant CStr but it’s still a fat pointer.

Anyhow, i sometimes need to deal with null-terminated arrays in no_std code.

Maybe in future, null-terminated could be officially adopted and exposed thru the std façade, but i’m not holding my breath :smile:


#4

I mean, of course one doesn’t pass CString/CStr to foreign code directly, but result of as_ptr() -> *mut c_char instead.

I see. A good point!