Crate seestr

Crate seestr 

Source
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 null

Can 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§

AllocError
Returned from BufIn::try_of_bytes.
BufIn
Pointer-wide, owned handle to a nul-terminated buffer, which is freed on Drop.
Libclibc
Use libc’s allocation functions.
NulTerminated
A buffer that terminates at a nul byte, with a length less than isize::MAX.

Traits§

Allocator
Safety

Type Aliases§

Buflibc
Pointer-wide, owned handle to a nul-terminated buffer, allocated with malloc, which is free-ed on Drop.