我现在正在使用Warp with Rust编写一个应用程序,我想把它打包到一个独立的可执行文件中,但顾名思义,warp::fs::dir
似乎是从文件系统加载它.
有没有办法把静态文件Bundle 成扭曲滤镜?或者,是否有其他框架支持这一点?
只是为了澄清一下,我说的"Bundle "指的是这样的东西:
fn get_file() -> &str {
include_str!("file.html")
}
我现在正在使用Warp with Rust编写一个应用程序,我想把它打包到一个独立的可执行文件中,但顾名思义,warp::fs::dir
似乎是从文件系统加载它.
有没有办法把静态文件Bundle 成扭曲滤镜?或者,是否有其他框架支持这一点?
只是为了澄清一下,我说的"Bundle "指的是这样的东西:
fn get_file() -> &str {
include_str!("file.html")
}
看起来你在寻找static_dir
crate个宏中的static_dir
个.
引用documentation人的话:
创建一个筛选器,该筛选器为基址
$path
处的目录提供服务 请求路径.它的行为很像Warp的
fs::dir
,但不是提供来自 运行时的文件系统,将嵌入要提供服务的目录 在编译时转换为您的二进制文件.如果提供的路径是相对路径,则它将相对于项目 根目录(根据
CARGO_MANIFEST_DIR
环境变量).use static_dir::static_dir; use warp::Filter; // Matches requests that start with `/static`, and then uses the // rest of that path to lookup and serve a file from `/www/static`. let route = warp::path("static").and(static_dir!("/www/static")); // For example: // - `GET /static/app.js` would serve the file `/www/static/app.js` // - `GET /static/css/app.css` would serve the file `/www/static/css/app.css`