How to send a file included in include_bytes! How is the reaction of iron?

I am trying to send a file that I included in binary with include_bytes!in an Iron application. I want to get one file for my application, and it needs only a few HTML, CSS and JS files. Here is a small test setup in which I play:

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, this does not work, because it index_htmlhas type&[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)))

Since I'm completely new to Rust and Iron, I have no idea how to approach this. I tried to learn something from Iron documents, but I think my knowledge of Rust is not enough to really understand them, especially what should be in this trait modifier::Modifier.

? -, - Modifier?

+4
1

impl:

src/main.rs:13:12: 13:26 help: the following implementations were found:
src/main.rs:13:12: 13:26 help:   <&'a [u8] as modifier::Modifier<iron::response::Response>>

, index_html , , &'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();
}

, Modifier , , , . , Modifier<Response> iron::modifiers.

+7

Source: https://habr.com/ru/post/1625738/


All Articles