6 releases
0.1.5 | Nov 29, 2024 |
---|---|
0.1.4 | Nov 28, 2024 |
#363 in FFI
446 downloads per month
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;
}
lib.rs
:
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