-
Bug Reportcodeuse std::{net::SocketAddr, sync::Arc};
use axum::{
extract::{ConnectInfo, State},
http::HeaderMap,
response::Html,
routing::{get, post},
Router,
};
#[tokio::main]
async fn main() {
// let state = std::sync::Arc::new(String::new());
// build our application with a route
let app = Router::new()
.route("/", get(handler))
.route("/user", post(create_user))
// .with_state(state)
.into_make_service_with_connect_info::<SocketAddr>();
// run it
let listener = tokio::net::TcpListener::bind("127.0.0.1:3000")
.await
.unwrap();
println!("listening on {}", listener.local_addr().unwrap());
axum::serve(listener, app).await.unwrap();
}
async fn handler() -> Html<&'static str> {
Html("<h1>Hello, World!</h1>")
}
async fn create_user(
ConnectInfo(sa): ConnectInfo<SocketAddr>,
// State(s): State<Arc<String>>,
body: Vec<u8>,
h: HeaderMap,
) -> Html<&'static str> {
println!("{} {}\n{:?}", "", body.len(), h);
Html("<h1>Hello, World!</h1>")
} errorserror[E0277]: the trait bound `fn(ConnectInfo<std::net::SocketAddr>, Vec<u8>, HeaderMap) -> impl Future<Output = Html<&'static str>> {create_user}: Handler<_, _>` is not satisfied
--> src/main.rs:18:30
|
18 | .route("/user", post(create_user))
| ---- ^^^^^^^^^^^ the trait `Handler<_, _>` is not implemented for fn item `fn(ConnectInfo<std::net::SocketAddr>, Vec<u8>, HeaderMap) -> impl Future<Output = Html<&'static str>> {create_user}` error[E0277]: the trait bound `fn(ConnectInfo<std::net::SocketAddr>, HeaderMap, Vec<u8>) -> impl Future<Output = Html<&'static str>> {create_user}: Handler<_, _>` is not satisfied
--> src/main.rs:18:30
|
18 | .route("/user", post(create_user))
| ---- ^^^^^^^^^^^ the trait `Handler<_, _>` is not implemented for fn item `fn(ConnectInfo<std::net::SocketAddr>, HeaderMap, Vec<u8>) -> impl Future<Output = Html<&'static str>> {create_user}`
| |
| required by a bound introduced by this call Version0.7.5 |
Beta Was this translation helpful? Give feedback.
Answered by
jplatte
Jun 21, 2024
Replies: 1 comment 1 reply
-
Hey, You can refer to Debugging handler type errors to get more insights into fixing issues like this yourself. |
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
biluohc
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hey,
Vec<u8>
does not implementFromRequest
. To extract the raw bytes of the HTTP body, use theBytes
type.You can refer to Debugging handler type errors to get more insights into fixing issues like this yourself.