#ffi #transparent #nul #semantic #nul-terminated #no-alloc #c-str

no-std seestr

pointer-wide nul-terminated strings with ownership semantics

6 releases

0.1.5 Nov 29, 2024
0.1.4 Nov 28, 2024

#1999 in Rust patterns

Download history 13/week @ 2025-02-11 13/week @ 2025-02-18 1/week @ 2025-02-25 1/week @ 2025-03-04

150 downloads per month

Apache-2.0 OR MIT

19KB
385 lines

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;
}

Dependencies

~43KB