Name | Date | Size | #Lines | LOC | ||
---|---|---|---|---|---|---|
.. | 20-Jan-2022 | - | ||||
src/ | H | 20-Jan-2022 | - | 292 | 235 | |
tests/ | H | 20-Jan-2022 | - | 142 | 112 | |
.cargo-checksum.json | H A D | 03-May-2022 | 89 | 1 | 1 | |
Cargo.toml | H A D | 20-Jan-2022 | 1,011 | 36 | 32 | |
LICENSE | H A D | 20-Jan-2022 | 1 KiB | 26 | 22 | |
README.md | H A D | 20-Jan-2022 | 943 | 31 | 21 |
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