Hi!
I'm trying to write a simple web server using warp.
As a first step it should serve all files except one particular type.
I found a similar example in the warp documentation at File in warp::filters::fs - Rust, but when I try to do the same thing in my code, it doesn't compile.
Here's my tokio::main that compiles:
let repository_path = ".";
let addr = "0.0.0.0:8000";
let socket_address: SocketAddr = addr.parse().expect("valid socket address");
let static_files = warp::any()
.and(warp::fs::dir(repository_path));
let server = warp::serve(static_files).try_bind(socket_address);
I followed the example linked above and just added a map, and then it doesn't compile:
let static_files = warp::any()
.and(warp::fs::dir(repository_path))
.map( |reply: warp::filters::fs::File| {
if reply.path().ends_with(".md") {
warp::reply::with_header(reply, "Content-Type", "text/MY_markdown").into_response()
} else {
reply.into_response()
};
},
);
I get:
error[E0277]: the trait bound `(): warp::Reply` is not satisfied
--> src/main.rs:34:18
|
34 | let server = warp::serve(static_files).try_bind(socket_address);
| ^^^^^^^^^^^ the trait `warp::Reply` is not implemented for `()`
|
= note: required because of the requirements on the impl of `warp::Reply` for `((),)`
note: required by a bound in `warp::serve`
--> /Users/wiz/.cargo/registry/src/github.com-1ecc6299db9ec823/warp-0.3.2/src/server.rs:26:17
|
26 | F::Extract: Reply,
| ^^^^^ required by this bound in `warp::serve`
error[E0277]: the trait bound `(): warp::Reply` is not satisfied
--> src/main.rs:34:44
|
34 | let server = warp::serve(static_files).try_bind(socket_address);
| ^^^^^^^^ the trait `warp::Reply` is not implemented for `()`
|
= note: required because of the requirements on the impl of `warp::Reply` for `((),)`
note: required by a bound in `warp::Server::<F>::try_bind`
--> /Users/wiz/.cargo/registry/src/github.com-1ecc6299db9ec823/warp-0.3.2/src/server.rs:127:35
|
127 | <F::Future as TryFuture>::Ok: Reply,
| ^^^^^ required by this bound in `warp::Server::<F>::try_bind`
For more information about this error, try `rustc --explain E0277`.
Can someone please explain the warning to me so I can fix it?
Is the example incorrect or am I doing something wrong/missing something?
Thanks for reading so far!