Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

iron-gdc error #2

Closed
simoneromano96 opened this issue Jan 30, 2018 · 3 comments
Closed

iron-gdc error #2

simoneromano96 opened this issue Jan 30, 2018 · 3 comments

Comments

@simoneromano96
Copy link

Hello, I'm having a compiler problem, running on windows 10 with C++ build tools 2017.
Book's Pages: 18-19.

Terminal Output:

$ cargo run
Compiling iron-gdc v0.1.0 (file:///C:/Users/Simone%20Romano/Desktop/git/rust/iron-gdc)
error: cannot find macro mime! in this scope
--> src\main.rs:21:22
|
21 | response.set_mut(mime!(Text/Html; Charset=Utf8));
| ^^^^

error: aborting due to previous error

error: Could not compile iron-gdc.

To learn more, run the command again with --verbose.

Code:

extern crate iron;
#[macro_use] extern crate mime;

use iron::prelude::*;
use iron::status;

fn main() 
{
    let port = 3000;
    let hostname = "localhost:" + port.to_string();
    println!("Serving on http://{}...", hostname);

    Iron::new(get_form).http(hostname).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; Charset=Utf8));
    response.set_mut(r#"
        <title> GDC Calculator </title>
        <form action="/gdc" method="post">
            <input type="text" name="n">
            <input type="text" name="n">
            <button type="submit"> Compute GDC </button>
        </form>
    "#);

    Ok(response)
}
@jimblandy
Copy link
Contributor

Can I see your Cargo.toml file? I'm curious which version of the mime crate you're using.

@simoneromano96
Copy link
Author

I left mime = * thinking it would select the latest version and evidently, it selected the first available version. Using the latest exact version made the program compile and work as expected. I read more about cargo in the Rust's documentation; if I understood right cargo will select automatically the latest version available if there are no major changes since the version specified in the .toml file, right?
Sorry for bringing this false problem up.
Thank you for the good book

@jimblandy
Copy link
Contributor

You're welcome!

The '*' version number says that any version will do, including major version upgrades. Cargo will choose the newest available, and then stick with that version until you run cargo update.

In this case, the newest version of the mime crate is currently 0.3.5. As of 0.3.0, the mime crate no longer exports a mime! macro. Page 186 explains the rules for version numbers starting with zero; in short, 0.3.5 is not compatible with 0.2.3, as you discovered.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants