i'm trying send file included in binary include_bytes! in iron application. want end single file application , needs few html, css , js files. here's small test setup i'm fiddling with:
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(); } of course, doesn't work since index_html of type &[u8; 78]
src/main.rs:16:12: 16:26 error: trait `modifier::modifier<iron::response::response>` not implemented type `&[u8; 78]` [e0277] src/main.rs:16 ok(response::with((content_type, status::ok, index_html))) since i'm quite new rust , iron, don't have idea how approach this. tried learn iron docs think rust knowledge not sufficient understand them, modifier::modifier trait supposed be.
how can achieve this? can covert type of static resource iron accept or need implement modifier trait somehow?
the compiler suggests alternative impl:
src/main.rs:13:12: 13:26 help: following implementations found: src/main.rs:13:12: 13:26 help: <&'a [u8] modifier::modifier<iron::response::response>> to ensure slice lives long enough, it's easier replace index_html variable global constant, , since must specify type of constants, let's specify &'static [u8].
extern crate iron; use iron::prelude::*; use iron::status; use iron::mime::mime; const index_html: &'static [u8] = include_bytes!("static/index.html"); fn main() { 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(); } by way, tried find implementations modifier in documentation, think they're not listed, unfortunately. however, found implementations modifier<response> in the source iron::modifiers module.
Comments
Post a Comment