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

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 :relaxed:

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

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:

1 Like

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!