1 个不稳定版本

0.7.3 2023 年 9 月 24 日

#6 in #include-dir

Download history 82/week @ 2024-03-11 108/week @ 2024-03-18 89/week @ 2024-03-25 103/week @ 2024-04-01 80/week @ 2024-04-08 107/week @ 2024-04-15 137/week @ 2024-04-22 156/week @ 2024-04-29 107/week @ 2024-05-06 112/week @ 2024-05-13 175/week @ 2024-05-20 86/week @ 2024-05-27 78/week @ 2024-06-03 62/week @ 2024-06-10 84/week @ 2024-06-17 89/week @ 2024-06-24

325 每月下载量
5 个 Crates 中使用(通过 comfy_include_dir

MIT 许可证

12KB
301

include_dir

Continuous Integration license Crates.io Docs.rs

include_str!()include_bytes!() 宏的进化版,用于将整个目录树嵌入到您的二进制文件中。

渲染文档

入门指南

include_dir!() 宏与常规的 include_str!()include_bytes!() 宏非常相似。您将文件路径传递给宏,并将返回的值分配给某个 static 变量。

use include_dir::{include_dir, Dir};

static PROJECT_DIR: Dir = include_dir!("$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 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 功能)
  • 文件元数据(需要 metadata 功能)

待办事项列表

  • 压缩?

依赖项

~84KB