我正在尝试include_bytes!
在 Iron 应用程序中发送一个包含在二进制文件中的文件。我想为我的应用程序提供一个文件,它只需要很少的 HTML、CSS 和 JS 文件。这是我正在摆弄的一个小型测试设置:
extern crate iron;
use iron::prelude::*;
use iron::status;
use iron::mime::Mime;
fn main() {
let index_html = include_bytes!("static/index.html");
println!("Hello, world!");
Iron::new(| _: &mut Request| {
let content_type = "text/html".parse::<Mime>().unwrap();
Ok(Response::with((content_type, status::Ok, index_html)))
}).http("localhost:8001").unwrap();
}
当然,这不起作用,因为index_html
它是类型&[u8; 78]
src/main.rs:16:12: 16:26 error: the trait `modifier::Modifier<iron::response::Response>` is not implemented for the type `&[u8; 78]` [E0277]
src/main.rs:16 Ok(Response::with((content_type, status::Ok, index_html)))
由于我对 Rust 和 Iron 很陌生,所以我不知道如何处理这个问题。我试图从 Iron 文档中学习一些东西,但我认为我的 Rust 知识不足以真正理解它们,尤其是这个modifier::Modifier
特征应该是什么。
我怎样才能做到这一点?我可以将我的静态资源的类型转换为 Iron 可以接受的东西,还是我需要以Modifier
某种方式实现这个特性?