我正在尝试String
将warp::server().run()
函数作为监听地址。但我不知道如何实现Into<SocketAddr>
字符串。
代码
use warp::Filter;
#[tokio::main]
async fn main() {
// GET /hello/warp => 200 OK with body "Hello, warp!"
let hello = warp::path!("hello" / String)
.map(|name| format!("Hello, {}!", name));
warp::serve(hello)
.run("127.0.0.1:3030")
.await;
}
错误
error[E0277]: the trait bound `std::net::SocketAddr: From<&str>` is not satisfied
--> src/server/mod.rs:24:29
|
24 | warp::serve(routes).run("127.0.0.1:3030").await;
| ^^^ the trait `From<&str>` is not implemented for `std::net::SocketAddr`
|
= help: the following implementations were found:
<std::net::SocketAddr as From<(I, u16)>>
<std::net::SocketAddr as From<SocketAddrV4>>
<std::net::SocketAddr as From<SocketAddrV6>>
= note: required because of the requirements on the impl of `Into<std::net::SocketAddr>` for `&str`