#编译时 #文件名 # #名称 #解析 #枚举

get_files_macro

A Rust宏,可以在编译前解析目录的文件名。

2个版本

0.1.3 2023年12月28日
0.1.2 2023年12月28日
0.1.1 2023年12月28日
0.1.0 2023年12月28日

#609 in 过程宏

MIT 许可证

11KB
217

get_files_macro

A Rust宏,可以在编译前解析目录的文件名。

用法

// This scenario is meant to be executed from this repo's root

let file_names = get_files!(true, true, true, true, true, "/", "./test");
// ^^^^^^^^^^^ -> Vec<&str>

let test_names = vec![
    "testfile1.test",
    "testfile2.test",
    "zzz",
    "zzz/testfile3.test",
    ".testfile.test",
    "testfile.link",
];

assert_eq!(file_names.len(), test_names.len());
for (index, file_name) in file_names.into_iter().enumerate() {
    assert_eq!(file_name, test_names[index]);
}

println!("All tests passed!");

状态

部署状态: 部署

为什么?

我想扩展sqlx,使其能够检查数据库迁移是否更新。为了做到这一点,我需要在编译前获取目录中所有文件的名称。我没有找到做到这一点的方法,所以我就编写了这个宏。

依赖关系

~250–690KB
~17K SLoC