Expand description
Pointer-wide nul-terminated strings for use in FFI.
The following C API:
char *create(void); // may return nul
void destroy(char *);
char *get_name(struct has_name *); // may return nul
char *version(void); // never nullCan be transcribed as follows:
extern "C" {
fn create() -> Option<Buf>;
fn destroy(_: Buf);
fn get_name(_: &HasName) -> Option<&NulTerminated>;
fn version() -> &'static NulTerminated;
}As opposed to:
extern "C" {
fn create() -> *mut c_char;
fn destroy(_: *mut c_char);
fn get_name(_: *mut HasName) -> *mut c_char;
fn version() -> *mut c_char;
}Structs§
- Alloc
Error - Returned from
BufIn::try_of_bytes. - BufIn
- Pointer-wide,
owned handle to a
nul-terminated buffer, which is freed onDrop. - Libc
libc - Use
libc’s allocation functions. - NulTerminated
- A buffer that terminates at a nul byte,
with a length less than
isize::MAX.
Traits§
- Allocator
- Safety