Read files macro for loading reading files to string at compile-time
Makefile for formatting and linting Workspace for subcrates. Moved crates to subdir and moved subcrate configs to workspace.*
This commit is contained in:
34
crates/read_files/src/lib.rs
Normal file
34
crates/read_files/src/lib.rs
Normal file
@ -0,0 +1,34 @@
|
||||
extern crate proc_macro;
|
||||
use proc_macro::TokenStream;
|
||||
|
||||
use syn::parse_macro_input;
|
||||
|
||||
use crate::read_files::read_files_to_string_impl;
|
||||
|
||||
mod read_files;
|
||||
|
||||
/// Read files from a directory into a HashMap.
|
||||
/// The key is the file path relative to the root directory.
|
||||
/// The value is the file contents as a string.
|
||||
/// # Arguments
|
||||
/// * `path` - The directory to search for files, relative to the root directory.
|
||||
/// * `pattern` - The regex pattern to match files against. If missing, all files are matched.
|
||||
/// # Returns
|
||||
/// A HashMap containing the file paths and contents.
|
||||
/// # Example
|
||||
/// ```
|
||||
/// use read_files::read_files_to_string;
|
||||
///
|
||||
/// let files = read_files_to_string!("./src", ".rs$");
|
||||
/// assert!(!files.is_empty());
|
||||
/// ```
|
||||
/// # Panics
|
||||
/// If the path is empty. \
|
||||
/// If the pattern is invalid. \
|
||||
/// If the path does not exist. \
|
||||
/// If there are unexpected tokens. \
|
||||
#[proc_macro]
|
||||
pub fn read_files_to_string(input: TokenStream) -> TokenStream {
|
||||
let args = parse_macro_input!(input as read_files::Args);
|
||||
read_files_to_string_impl(args)
|
||||
}
|
Reference in New Issue
Block a user