https://github.com/upsuper/include_cstr
Macro for building static CStr reference from file content
https://github.com/upsuper/include_cstr
Last synced: 4 months ago
JSON representation
Macro for building static CStr reference from file content
- Host: GitHub
- URL: https://github.com/upsuper/include_cstr
- Owner: upsuper
- License: mit
- Created: 2021-04-22T12:14:02.000Z (about 4 years ago)
- Default Branch: master
- Last Pushed: 2021-04-22T12:14:20.000Z (about 4 years ago)
- Last Synced: 2025-02-28T05:53:09.518Z (4 months ago)
- Language: Rust
- Size: 5.86 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# include_cstr
A macro for getting `&'static CStr` from a file.
This macro checks whether the content of the given file 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.46 and above.
It currently requires nightly compiler for [`proc_macro_span`][proc_macro_span] feature
for resolving relative path to the file,
so that it can be used in a similar way as `include_str!` and `include_bytes!` macro.[proc_macro_span]: https://doc.rust-lang.org/unstable-book/library-features/proc-macro-span.html
## Example
```rust
use include_cstr::include_cstr;
use std::ffi::CStr;let example = include_cstr!("example.txt");
assert_eq!(example, CStr::from_bytes_with_nul(b"content in example.txt\0").unwrap());
```