Crate seasick

Source
Expand description

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>());

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

Modules§

till_null
Iterators for nul-terminated arrays of pointers.

Macros§

assert_abimacros
Assert that the ABI of two functions are compatible.

Structs§

AllocError
Heap allocation failure.
CFor
Iterator returned by cfor.
Libclibc
An Allocator which uses libc’s allocation functions.
SeaArray
A fixed-sized array that MAY be truncated by an interior null.
SeaBoxIn
Owned, aligned pointer to a T, which is freed on Drop.
SeaStr
A run of bytes that is guaranteed to terminate at nul.
SeaStringIn
Pointer-wide, owned handle to a nul-terminated buffer, which is freed on Drop.
WriteBufferalloc
A growable, nul-terminated UTF-8 buffer which implements fmt::Write.

Traits§

Allocator
A set of free allocation functions.
TransmuteFrom
Transmute between two types that have the same ABI.
TransmuteMutFrom
Transmute between mutable references of two types that have compatible ABIs.
TransmuteRefFrom
Transmute between references of two types that have compatible ABIs.

Functions§

cfor
Emulate a C-style for loop.

Type Aliases§

SeaBoxlibc
Owned, aligned pointer to a T allocated with malloc, which is free-ed on Drop.
SeaStringlibc
Pointer-wide, owned handle to a nul-terminated buffer, allocated with malloc, which is free-ed on Drop.

Derive Macros§

TransmuteFrommacros
Implement TransmuteFrom between two types.
TransmuteMutFrommacros
TransmuteRefFrommacros