3 releases

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

#1153 in Data structures

Download history 96/week @ 2024-04-07 8/week @ 2024-04-14 228/week @ 2024-05-12 15/week @ 2024-05-19 153/week @ 2024-06-09

173 downloads per month
Used in fmod-oxide

MPL-2.0 license

585 lines

Like camino, but for C strings


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