20 releases

0.2.11 Sep 24, 2022
0.2.10 Feb 25, 2022
0.2.9 Sep 24, 2021
0.2.8 Dec 6, 2020
0.1.3 Feb 14, 2018

#77 in Procedural macros

Download history 14666/week @ 2023-11-20 14649/week @ 2023-11-27 14590/week @ 2023-12-04 11316/week @ 2023-12-11 6417/week @ 2023-12-18 7654/week @ 2023-12-25 15268/week @ 2024-01-01 12468/week @ 2024-01-08 19491/week @ 2024-01-15 15070/week @ 2024-01-22 22397/week @ 2024-01-29 16122/week @ 2024-02-05 14715/week @ 2024-02-12 15961/week @ 2024-02-19 14652/week @ 2024-02-26 17685/week @ 2024-03-04

64,715 downloads per month
Used in 61 crates (39 directly)

MIT license

12KB
243 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.64 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.64 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

~83KB