Function not found in module

I am new to RUST and the book I am reading has an example program that builds a web server that serves a page with some form. It uses dependencies and one is the Iron crate. When I run the program I get an error cannot find function new in module iron but looking at the crate the function is there so why can it not find it?

Could you please share some code to help us figure out what the problem is? There is no explicit new function in the iron crate.

Thanks here is the code

extern crate iron; #[macro_use] 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{
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)

}
</code

Perhaps you meant Iron (The struct) and not iron the crate. Try

fn main() {
    println!("Serving on http://localhost:3000...");
    Iron::new(get_form).http("localhost:3000").unwrap();
}

instead.

That solved it thanks a lot.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.