• Home
  • History
  • Annotate
Name Date Size #Lines LOC

..20-Jan-2022-

src/H20-Jan-2022-292235

tests/H20-Jan-2022-142112

.cargo-checksum.jsonH A D03-May-202289 11

Cargo.tomlH A D20-Jan-20221,011 3632

LICENSEH A D20-Jan-20221 KiB2622

README.mdH A D20-Jan-2022943 3121

README.md

1# cstr
2
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)
6
7<!-- cargo-sync-readme start -->
8
9A macro for getting `&'static CStr` from literal or identifier.
10
11This macro checks whether the given literal is valid for `CStr`
12at compile time, and returns a static reference of `CStr`.
13
14This macro can be used to to initialize constants on Rust 1.46 and above.
15
16## Example
17
18```rust
19use cstr::cstr;
20use std::ffi::CStr;
21
22let test = cstr!(b"hello\xff");
23assert_eq!(test, CStr::from_bytes_with_nul(b"hello\xff\0").unwrap());
24let test = cstr!("hello");
25assert_eq!(test, CStr::from_bytes_with_nul(b"hello\0").unwrap());
26let test = cstr!(hello);
27assert_eq!(test, CStr::from_bytes_with_nul(b"hello\0").unwrap());
28```
29
30<!-- cargo-sync-readme end -->
31