2 releases

new 0.1.2 May 13, 2024
0.1.1 May 13, 2024
0.1.0 Apr 11, 2024

#1227 in Data structures

Download history 102/week @ 2024-04-08 2/week @ 2024-04-15

104 downloads per month

MPL-2.0 license

38KB
585 lines

Like camino, but for C strings


lib.rs:

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.

No runtime deps

Features