include_cstr 0.1.0

Macro for building static CStr reference from file content
Documentation
  • Coverage
  • 50%
    1 out of 2 items documented1 out of 2 items with examples
  • Size
  • Source code size: 22.06 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 271.17 kB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 4s Average build duration of successful builds.
  • all releases: 4s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • upsuper/include_cstr
    1 0 0
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • upsuper

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 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.

Example

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());