rust rust_embed 方便资源嵌入到rust 应用程序中的包

rust-embed是一个自定义的derive macro,可以方便的将资源嵌入到rust 引用程序中

参考使用

use rust_embed::Embed;

#[derive(Embed)]
#[folder = "examples/public/"]
#[prefix = "prefix/"]
struct Asset;

fn main() {
  let index_html = Asset::get("prefix/index.html").unwrap();
  println!("{:?}", std::str::from_utf8(index_html.data.as_ref()));

  for file in Asset::iter() {
      println!("{}", file.as_ref());
  }
}

说明

有不少应用使用了此包,比如ratch-job 等

参考资料

https://crates.io/crates/rust-embed

https://git.sr.ht/~pyrossh/rust-embed

https://github.com/ratch-job/ratch-job

posted on 2025-08-26 08:00  荣锋亮  阅读(34)  评论(0)    收藏  举报

导航