#line #file #macro #read-file #add #procedural #include-lines

macro include-lines-proc

Procedural macros for the include-lines crate. Please add that crate instead.

2 stable releases

1.1.0 Feb 16, 2023
1.0.0 Feb 16, 2023

#84 in #read-file

Download history 49/week @ 2024-05-27 45/week @ 2024-06-03 43/week @ 2024-06-10 50/week @ 2024-06-17 95/week @ 2024-06-24 56/week @ 2024-07-01 38/week @ 2024-07-08 66/week @ 2024-07-15 54/week @ 2024-07-22 322/week @ 2024-07-29 327/week @ 2024-08-05 697/week @ 2024-08-12 875/week @ 2024-08-19 750/week @ 2024-08-26 712/week @ 2024-09-02 1249/week @ 2024-09-09

3,616 downloads per month
Used in 3 crates (via include-lines)

MIT/Apache

3KB

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::include_lines;
let lines = include_lines!("file.txt");

For the example file, this expands to:

let lines = [
    "these",
    "are",
    "file",
    "lines",
];

Read in a file and store it an an array of type [String]

use include_lines::include_lines_s;
let lines = include_lines_s!("file.txt");

For the example file, this expands to:

let lines = [
    String::from("these"),
    String::from("are"),
    String::from("file"),
    String::from("lines"),
];

Get the number of lines in a file at compile time as type usize

use include_lines::count_lines;
let num_lines = count_lines!("file.txt");

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 include_lines::{static_include_lines};
static_include_lines!(LINES, "file.txt");

For the example file, this expands to:

static LINES: [&str; 4] = [
    "these",
    "are",
    "file",
    "lines",
];

Dependencies

~1.5MB
~35K SLoC