5 个版本
0.1.4 | 2024 年 5 月 31 日 |
---|---|
0.1.3 | 2024 年 5 月 31 日 |
0.1.2 | 2024 年 5 月 22 日 |
0.1.1 | 2024 年 2 月 22 日 |
0.1.0 | 2024 年 2 月 22 日 |
#13 in #bundling
在 embd 中使用
8KB
112 行
embd-rs
一个超级简单的文件和目录嵌入 Crates,在调试模式下从文件系统中加载文件,允许在不进行编译的情况下快速编辑和测试。
它也非常高效,在发布模式下将文件嵌入时不进行堆分配,利用 std::borrow::Cow
。
在发布模式下,它回退到 include_str!
、include_bytes!
和我们自己的自定义 include_dir!
-like 实现。
用法
将其添加到您的 Cargo.toml 中
[dependencies]
embd = "0.1"
然后您可以像这样使用此 Crates
let contents: Cow<'_, str> = embd::string!("path/to/file.txt");
let bytes: Cow<'_, [u8]> = embd::bytes!("path/to/image.png");
let dir: embd::Dir = embd::dir!("path/to");
let files: Vec<embd::File> = dir.flatten();
请注意,您需要启用 procmacro2_semver_exempt
cfg 选项才能使用此 Crates,您可以在项目根目录中的 .cargo/config.toml
中启用它,如下所示
[build]
rustflags = [ "--cfg", "procmacro2_semver_exempt" ]
待办事项
- 在调试模式下热重载文件。
- 不要依赖于
procmacro2_semver_exempt
。
许可证
Copyright (c) 2023-present RGBCube
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
依赖关系
~265–710KB
~17K SLoC