2 个版本
0.1.1 | 2023 年 2 月 16 日 |
---|---|
0.1.0 | 2023 年 2 月 16 日 |
在 开发工具 中排名第 1606
每月下载量 241 次
19KB
281 行
include_directory
是 include_str!()
和 include_bytes!()
宏的进化,可以将整个目录树嵌入到您的二进制文件中。
这是从 include_dir
crate 分支出来的,可以在编译时收集文件的 mime 类型,并在运行时访问。
渲染的文档
入门
include_directory!()
宏的工作方式与常规的 include_str!()
和 include_bytes!()
宏非常相似。您向宏传递一个文件路径,并将返回的值赋给某个 static
变量。
use include_directory::{include_directory, Dir};
static PROJECT_DIR: Dir = include_directory!("$CARGO_MANIFEST_DIR");
// of course, you can retrieve a file by its full path
let lib_rs = PROJECT_DIR.get_file("src/lib.rs").unwrap();
// you can get the mimetype by doing
let mimetype = lib_rs.mimetype();
// you can also inspect the file's contents
let body = lib_rs.contents_utf8().unwrap();
assert!(body.contains("SOME_INTERESTING_STRING"));
// you can search for files (and directories) using glob patterns
#[cfg(feature = "glob")]
{
let glob = "**/*.rs";
for entry in PROJECT_DIR.find(glob).unwrap() {
println!("Found {}", entry.path().display());
}
}
特性
- 在编译时将目录树嵌入到您的二进制文件中
- 在嵌入的目录中查找文件
- 使用 glob 模式搜索文件(需要
globs
功能) - 在编译时收集文件的 mime 类型
- 文件元数据(需要
metadata
功能)
待办事项列表
- 压缩?
依赖项
~225–315KB