プロジェクトを作成します。
cargo new poem-hello
cd poem-hello
Cargo.toml を編集します。
[dependencies]
poem = "1"
tokio = { version = "1", features = ["macros", "rt-multi-thread"] }macro は #[tokio::main] を使うために必要です。
src/main.rs を編集します。
use poem::{get, handler, Route, Server};
use poem::listener::TcpListener;
#[handler]
fn hello() -> &'static str {
"Hello, world!"
}
#[tokio::main]
async fn main() -> Result<(), std::io::Error> {
let app = Route::new().at("/", get(hello));
Server::new(TcpListener::bind("127.0.0.1:3000"))
.run(app)
.await
}
ビルドおよび起動する
cargo run