include-lines
Rust macros for reading in all lines from a file at compile time. This can be very useful for loading static data.
Examples
For the examples, there is a file file.txt
in the same directory as the project's Cargo.toml file:
these
are
file
lines
Read in a file and store it an an array of type [&'static str]
use include_lines;
let lines = include_lines!;
For the example file, this expands to:
let lines = ;
Read in a file and store it an an array of type [String]
use include_lines_s;
let lines = include_lines_s!;
For the example file, this expands to:
let lines = ;
Get the number of lines in a file at compile time as type usize
use count_lines;
let num_lines = count_lines!;
For the example file, this expands to:
let num_lines = 4usize;
Create a static array from a file at compile time
You can use the static_include_lines!
and static_include_lines_s!
macros to initialize static text arrays at compile time:
use ;
static_include_lines!;
For the example file, this expands to:
static LINES: = ;