Bug 1687945 [wpt PR 27273] - [resources] Fix conftest.py for pytest>6, a=testonly
[gecko.git] / third_party / rust / cstr / README.md
blobe8950e7d11ab3ca23011c0a81f5ed5ccea95f0a6
1 # cstr
3 [![CI](https://github.com/upsuper/cstr/workflows/CI/badge.svg)](https://github.com/upsuper/cstr/actions)
4 [![Crates.io](https://img.shields.io/crates/v/cstr.svg)](https://crates.io/crates/cstr)
5 [![Docs](https://docs.rs/cstr/badge.svg)](https://docs.rs/cstr)
7 <!-- cargo-sync-readme start -->
9 A macro for getting `&'static CStr` from literal or identifier.
11 This macro checks whether the given literal is valid for `CStr`
12 at compile time, and returns a static reference of `CStr`.
14 This macro can be used to to initialize constants on Rust 1.46 and above.
16 ## Example
18 ```rust
19 use cstr::cstr;
20 use std::ffi::CStr;
22 let test = cstr!(b"hello\xff");
23 assert_eq!(test, CStr::from_bytes_with_nul(b"hello\xff\0").unwrap());
24 let test = cstr!("hello");
25 assert_eq!(test, CStr::from_bytes_with_nul(b"hello\0").unwrap());
26 let test = cstr!(hello);
27 assert_eq!(test, CStr::from_bytes_with_nul(b"hello\0").unwrap());
28 ```
30 <!-- cargo-sync-readme end -->