Understanding RUST Programs: cannot find macro `mime` in this scope

Asked 2 years ago, Updated 2 years ago, 134 views

I'm currently learning RUST, but I can't get out of the following error:
How can I get out of it?

error message

 error:cannot find macro `mime` in this scope
  -->src/main.rs:16:18
   |
16 | response.set_mut (mime! (Text/Html; Charset=Utf8));

Related codes are as follows:

.toml

 [package]
name = "iron-gcd"
version = "0.1.0"
authorities=["<>" ]

[Dependencies]
iron="0.5.1"
mime = "0.3.16"
router = "0.5.1"
urlencoded="0.5.0"

main

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

useiron::prelude::*;
useiron::status;

US>fnmain(){
    println!("Serving on http://localhoset:3000...");
Iron::new(get_form).http("localhost:3000").unwrap();
}

fnget_form(_request:&mutRequest)->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> GCD Calculator</title>
<form action="/gcd" method="post">
<input type="text" name="n"/>
<input type="text" name="n"/>
<button type="submit">compute GCD</button>
</form>
"#);
Ok (response)
}

rust

2022-09-30 19:18

2 Answers

Hello, it looks like you are referring to the old code example.

mime macros are available up to mime0.2 series and are not available for your mime0.3.16.Also, since the iron 0.5 series depends on mime 0.2 series, the compilation goes through by rewriting the mime="0.3.16" part of Cargo.toml with mime="0.2".

The above problem will be solved for the time being, but I would like to point out other points.

  • iron 0.5.1 was released 3 years ago and the latest version of iron is 0.6.1
    • To put it a little bit more, iron is a less popular framework these days, but that's another story
  • The current Rust has moved to 2018 edition, and extern rate and #[macro_use] are rarely used.
    • However, if the library has not migrated properly, I may use it
  • To put it a little bit more, iron is a less popular framework these days, but that's another story
  • However, if the library has not migrated properly, I may use it

If you go to the iron and mime repositories, it seems that there are quite a few changes from the latest version that is currently released, so I'll stop posting old codes here again, but if you're interested, please check out how to write new ones.


2022-09-30 19:18

Since mimecrate obsoleted the mime! macro in 0.3, setting the mime version of Cargo.toml to 0.2.6 should make the mime! macro usable

macro.


2022-09-30 19:18

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.