Crates.io | include-lines |
lib.rs | include-lines |
version | 1.1.2 |
source | src |
created_at | 2022-12-31 06:49:04.329253 |
updated_at | 2023-02-17 08:38:25.738427 |
description | Macros for reading in the lines of a file at compile time |
homepage | |
repository | https://github.com/hunterlawson/include-lines |
max_upload_size | |
id | 748271 |
size | 6,755 |
Rust macros for reading in all lines from a file at compile time. This can be very useful for loading static data.
For the examples, there is a file file.txt
in the same directory as the project's Cargo.toml file:
these
are
file
lines
[&'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",
];
[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"),
];
usize
use include_lines::count_lines;
let num_lines = count_lines!("file.txt");
For the example file, this expands to:
let num_lines = 4usize;
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",
];