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

no-std seasick

FFI-safe nul-terminated strings with ownership semantics

7 releases

0.2.2 Dec 21, 2024
0.2.1 Dec 20, 2024
0.1.3 Dec 20, 2024
0.1.0 Nov 30, 2024

#1028 in Rust patterns

Download history 139/week @ 2024-11-28 23/week @ 2024-12-05 102/week @ 2024-12-12 331/week @ 2024-12-19 3/week @ 2024-12-26

469 downloads per month

Apache-2.0 OR MIT

40KB
839 lines

FFI-safe types for writing and transcribing C APIs.

&CStr and CString are not FFI safe.

#[deny(improper_ctypes)]
extern "C" {
    fn concat(_: &CStr, _: &CStr) -> CString;
}

&SeaStr and SeaString are FFI-safe equivalents.

extern "C" {
    fn concat(_: &SeaStr, _: &SeaStr) -> SeaString;
}

They use the non-null niche which is filled by Option::None.

/** may return null */
char *foo(void);
extern "C" fn foo() -> Option<SeaString> { .. }
assert_eq!(size_of::<Option<SeaString>>(), size_of::<*mut c_char>());

SeaBox is an additional owned pointer type, with a pluggable Allocator.


lib.rs:

FFI-safe types for writing and transcribing C APIs.

&CStr and CString are not FFI safe.

#[deny(improper_ctypes)]
extern "C" {
    fn concat(_: &CStr, _: &CStr) -> CString;
}

&SeaStr and SeaString are FFI-safe equivalents.

extern "C" {
    fn concat(_: &SeaStr, _: &SeaStr) -> SeaString;
}

They use the non-null niche which is filled by Option::None.

/** may return null */
char *foo(void);
extern "C" fn foo() -> Option<SeaString> { .. }
assert_eq!(size_of::<Option<SeaString>>(), size_of::<*mut c_char>());

SeaBox is an additional owned pointer type, with a pluggable Allocator. till_null contains iterators for nul-terminated arrays of pointers.

Dependencies

~43KB