I am trying to run the examples from the book Programming Rust published by O'Reilly and I am stuck at making the following code compile successfully:
Cargo.toml
[package]
name = "gcd-online"
version = "0.1.0"
authors = ["Jignesh Gohel <abc@example.com>"]
edition = "2018"
[dependencies]
iron = "0.6.0"
mime = "0.3.12"
router = "0.6.0"
urlencoded = "0.6.0"
/src/main.rs
extern crate iron;
extern crate mime;
use iron::prelude::*;
use iron::status;
fn main() {
println!("Serving on http://localhost:3000...");
Iron::new(get_form).http("localhost:3000").unwrap();
}
fn get_form(_request: &mut Request) -> IronResult<Response> {
let mut response = Response::new();
response.set_mut(status::Ok);
response.set_mut(mime::TEXT_HTML_UTF_8);
response.set_mut(r#"
<title>GCD Calculator</title>
<form action="/gcd" method="post">
<input type="text" name="n" />
<input type="text" name="m" />
<button type="submit">Compute GCD</button>
</form>
"#);
Ok(response)
}
Output
Compiling gcd-online v0.1.0 (~/oreilly-programming-rust-book-examples/chapter-1/gcd-online)
error[E0277]: the trait bound `mime::Mime: iron::modifier::Modifier<iron::Response>` is not satisfied
--> src/main.rs:17:14
|
17 | response.set_mut(mime::TEXT_HTML_UTF_8);
| ^^^^^^^ the trait `iron::modifier::Modifier<iron::Response>` is not implemented for `mime::Mime`
My Cargo.toml uses latest version of dependencies, however book author uses following versions
[dependencies]
iron = "0.5.1"
mime = "0.2.3"
router = "0.5.1"
urlencoded = "0.5.0"
and as part of which author used following code
#[macro_use] extern crate mime;
fn get_form(_request: &mut Request) -> IronResult<Response> {
let mut response = Response::new();
response.set_mut(mime!(Text/Html; Charset=Utf8));
Ok(response)
}
I think the difference in versions is what is causing the compilation error.
I tried to go through the docs of the iron and mime crates but I couldn't figure out how to get past this error.