#macro #cstr

macro cstr

Macro for building static CStr reference

19 releases

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

#45 in Procedural macros

Download history 8240/week @ 2022-04-22 8598/week @ 2022-04-29 8724/week @ 2022-05-06 8714/week @ 2022-05-13 8513/week @ 2022-05-20 9042/week @ 2022-05-27 8663/week @ 2022-06-03 8621/week @ 2022-06-10 9402/week @ 2022-06-17 10002/week @ 2022-06-24 9660/week @ 2022-07-01 9053/week @ 2022-07-08 9197/week @ 2022-07-15 9675/week @ 2022-07-22 8628/week @ 2022-07-29 8659/week @ 2022-08-05

37,591 downloads per month
Used in 26 crates (20 directly)

MIT license

11KB
230 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.59 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.59 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

~105KB