4 个版本
0.1.4 | 2024年5月31日 |
---|---|
0.1.2 | 2024年5月22日 |
0.1.1 | 2024年2月22日 |
0.1.0 | 2024年2月22日 |
#413 in 文件系统
每月219次下载
11KB
172 代码行
embd-rs
一个超级简单的文件和目录嵌入 crate,在调试模式下从文件系统加载文件,允许快速编辑和测试循环,无需编译。
它也非常高效,在发布模式下嵌入文件时不进行堆分配,利用 std::borrow::Cow
。
在发布模式下,它回退到 include_str!
、include_bytes!
和我们自己的自定义 include_dir!
类似实现。
使用方法
将此内容添加到您的 Cargo.toml
[dependencies]
embd = "0.1"
然后您可以像这样使用此 crate
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 选项才能使用此 crate,您可以通过在项目根目录的 .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.
依赖关系
~270–720KB
~17K SLoC