2 个版本

0.1.1 2023 年 2 月 16 日
0.1.0 2023 年 2 月 16 日

开发工具 中排名第 1606

Download history 37/week @ 2024-03-13 51/week @ 2024-03-20 46/week @ 2024-03-27 88/week @ 2024-04-03 48/week @ 2024-04-10 30/week @ 2024-04-17 16/week @ 2024-04-24 7/week @ 2024-05-01 25/week @ 2024-05-08 34/week @ 2024-05-15 34/week @ 2024-05-22 36/week @ 2024-05-29 92/week @ 2024-06-05 63/week @ 2024-06-12 55/week @ 2024-06-19 22/week @ 2024-06-26

每月下载量 241

MIT 许可证

19KB
281

include_directory

Continuous Integration license Crates.io Docs.rs

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