cstr-enum
A crate for defining C-style string enums.
C APIs sometimes require string constants. One could define a bunch of &CStr
constants using the
constr_cstr
crate, but this becomes unergonomic with a large number of constants.
It also does not allow the type checking Rust's enums provide.
This crate provides two traits for converting between to and from &CStr
: AsCStr
and FromCStr
. It also provides
derive macros for implementing these traits on enums. The implementations provided
by the derive macros perform no allocations, using only static [u8]
buffers.
Example usage
use *;
use CStr;
use c_char;
assert_eq!;
let returned_from_c_api = from_bytes_with_nul.unwrap;
assert_eq!;
let returned_from_c_api = from_bytes_with_nul.unwrap;
assert_eq!;
License
Licensed under MIT
.