18 releases

0.2.9 Sep 24, 2021
0.2.8 Dec 6, 2020
0.2.5 Oct 1, 2020
0.2.1 Jul 17, 2020
0.1.3 Feb 14, 2018

#20 in Procedural macros

Download history 10633/week @ 2021-09-27 10678/week @ 2021-10-04 9701/week @ 2021-10-11 10028/week @ 2021-10-18 8977/week @ 2021-10-25 11846/week @ 2021-11-01 11145/week @ 2021-11-08 11556/week @ 2021-11-15 9417/week @ 2021-11-22 9444/week @ 2021-11-29 8954/week @ 2021-12-06 9505/week @ 2021-12-13 6946/week @ 2021-12-20 8005/week @ 2021-12-27 7886/week @ 2022-01-03 8806/week @ 2022-01-10

32,798 downloads per month
Used in 24 crates (17 directly)

MIT license

12KB
235 lines

cstr

CI Crates.io Docs

A macro for getting &'static CStr from literal or identifier.

This macro checks whether the given literal is valid for CStr at compile time, and returns a static reference of CStr.

This macro can be used to to initialize constants on Rust 1.46 and above.

Example

use cstr::cstr;
use std::ffi::CStr;

let test = cstr!(b"hello\xff");
assert_eq!(test, CStr::from_bytes_with_nul(b"hello\xff\0").unwrap());
let test = cstr!("hello");
assert_eq!(test, CStr::from_bytes_with_nul(b"hello\0").unwrap());
let test = cstr!(hello);
assert_eq!(test, CStr::from_bytes_with_nul(b"hello\0").unwrap());

lib.rs:

A macro for getting &'static CStr from literal or identifier.

This macro checks whether the given literal is valid for CStr at compile time, and returns a static reference of CStr.

This macro can be used to to initialize constants on Rust 1.46 and above.

Example

use cstr::cstr;
use std::ffi::CStr;

let test = cstr!(b"hello\xff");
assert_eq!(test, CStr::from_bytes_with_nul(b"hello\xff\0").unwrap());
let test = cstr!("hello");
assert_eq!(test, CStr::from_bytes_with_nul(b"hello\0").unwrap());
let test = cstr!(hello);
assert_eq!(test, CStr::from_bytes_with_nul(b"hello\0").unwrap());

Dependencies

~110KB