iron / staticfile

Static file-serving middleware for the Iron web framework.
MIT License
63 stars 56 forks source link

I get trait Handler not in scope for Static??? #101

Closed najamelan closed 6 years ago

najamelan commented 6 years ago

I just try to serve 1 static file, not mount a folder. I tried to figure out from the docs and examples how to do that, but didn't really find out, so looking in the code I saw Static implements handler, so I just try to forward the call to handle, but the compiler won't have it and I don't understand why. My handler in itself works.

use iron::prelude::*;
use iron::Handler;
use staticfile::Static;

pub struct Main;

impl Handler for Main
{
   fn handle( &self, req: &mut Request ) -> IronResult< Response > 
   {
      Static::new( "src/components/main/templates/index.htm" ).handle( req )
   }
}

I get the following error:

error[E0599]: no method named `handle` found for type `staticfile::Static` in the current scope
  --> src/components/main/mod.rs:20:60
   |
20 |   Static::new( "src/components/main/templates/index.htm" ).handle( req )
   |                                                            ^^^^^^
   |
   = note: the method `handle` exists but the following trait bounds were not satisfied:
           `staticfile::Static : iron::Handler`
   = help: items from traits can only be used if the trait is in scope
   = note: the following trait is implemented but not in scope, perhaps add a `use` for it:
           candidate #1: `use iron::middleware::Handler;`

The trait obviously is in scope, we're implementing it ourselves, so I'm a bit puzzled. Note that changing the use statement to include ::middleware:: don't change anything, nor adding a use to the handle method.

What am I doing wrong?

I can upload a full crate if needed for reproducing.

durka commented 6 years ago

You might have two different versions of iron (therefore two versions of Handler) -- check your Cargo.lock to be sure that your direct dependency and staticfile's dependency on iron are the same version.

najamelan commented 6 years ago

Ok, thanks for the hint, I didn't think of that at all. Surely that's what went wrong.