Expand description
UTF-8 equivalents of std’s C string types.
lanyard is an extension of the std::ffi module that adds new Utf8CStr and Utf8CString types.
They are like the standard library’s [CStr] and [CString] types, except they are guaranteed to be valid UTF-8.
Therefore they allow the ability to losslessly convert into strings, they implement Display, etc, etc.
The std::ffi types are not guaranteed to be valid UTF-8, which is the right decision for the standard library.
However, in FFI, it’s not uncommon to encounter APIs which expect all strings to be UTF-8. This generally requires
crate authors to convert between &str and CStr via CString between the Rust-C boundary (which allocates every time).
With UTF-8 C strings, the conversion between a &str and Utf8CStr are made explicit, and allocations can be minimized.
Macros§
Structs§
- Utf8C
Str - Representation of a borrowed UTF-8 C string.
This type is
#[repr(transparent)]and can be transmuted to a&safely.CStr - Utf8C
String - A type representing an owned, C-compatible, UTF-8, nul-terminated string with no nul bytes in the
middle.
This type is
#[repr(transparent)]and can be transmuted to a&safely.CString
Enums§
- From
Owned Utf8 With Nul - An error indicating that a nul byte was not in the expected position, or that there was invalid UTF-8.
- From
Utf8 Until Nul - An error indicating that no nul byte was present, or that there was invalid UTF-8.
- From
Utf8 With Nul - An error indicating that a nul byte was not in the expected position, or that there was invalid UTF-8.