Crate c_utf8[−][src]
Operations on UTF-8-encoded C strings.
The CUtf8
and CUtf8Buf
types are guaranteed to be:
-
Nul (Ø) terminated C strings in order to more safely ensure that C APIs only access memory that is properly owned.
-
Encoded as valid UTF-8, allowing for passing around native Rust
str
strings with ease.
Usage
This crate is available on crates.io and
can be used by adding the following to your project's
Cargo.toml
:
[dependencies]
c_utf8 = "0.1"
and this to your crate root (lib.rs
or main.rs
):
#[macro_use] // enables c_utf8! macro extern crate c_utf8;
Examples
A CUtf8
slice can be created via the c_utf8!
macro, which ensures it will always end with a trailing 0 byte:
use c_utf8::CUtf8; static MESSAGE: &CUtf8 = c_utf8!("Heyo!"); fn main() { let bytes = [72, 101, 121, 111, 33, 0]; assert_eq!(MESSAGE.as_bytes_with_nul(), &bytes); }
Macros
c_utf8 |
Creates a |
Structs
CUtf8 |
Like |
CUtf8Buf |
An owned, mutable UTF-8 encoded C string (akin to |
Enums
Error |
The error for converting types to |
Type Definitions
c_char |
Equivalent to C's |