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

no-std seasick

FFI-safe nul-terminated strings with ownership semantics

10 unstable releases (3 breaking)

Uses new Rust 2024

new 0.4.3 May 3, 2025
0.4.2 May 3, 2025
0.3.3 May 2, 2025
0.3.0 Apr 4, 2025
0.1.0 Nov 30, 2024

#864 in Rust patterns

Download history 2/week @ 2025-01-04 1/week @ 2025-01-11 30/week @ 2025-02-08 24/week @ 2025-02-15 3/week @ 2025-02-22 63/week @ 2025-03-29 73/week @ 2025-04-05 4/week @ 2025-04-12 1/week @ 2025-04-19

141 downloads per month

Apache-2.0 OR MIT

56KB
1K SLoC

Tools for implementing and transcribing C APIs.

&CStr, CString and Box are not FFI safe.

#[deny(improper_ctypes_definitions)]
extern "C" fn bad(_: &CStr, _: Box<u8>) -> CString { todo!() }

&SeaStr, SeaString and SeaBox are FFI-safe equivalents.

#[deny(improper_ctypes_definitions)]
extern "C" fn good(_: &SeaStr, _: SeaBox<u8>) -> SeaString { todo!() }

All are pointer-wide, with a non-null niche filled by Option::None.

assert_eq!(size_of::<SeaBox<u8>>(),         size_of::<*mut u8>());
assert_eq!(size_of::<Option<SeaBox<u8>>>(), size_of::<*mut u8>());
assert_eq!(size_of::<SeaString>(),          size_of::<*mut c_char>());
assert_eq!(size_of::<Option<SeaString>>(),  size_of::<*mut c_char>());

[trait@TransmuteFrom] is the culmination of this crate, for writing your own wrappers to C types. See its documentation for more.

Dependencies

~150KB