`async_trait` se re-exporta desde `pagetop` y se añade al preludio; ya no es necesario declararlo como dependencia en las extensiones. `initialize()` es ahora verdaderamente `async` (con `.await`), y `Application::new()` y `prepare()` pasan también a ser funciones `async`.
24 lines
578 B
Rust
24 lines
578 B
Rust
use pagetop::prelude::*;
|
|
|
|
struct HelloWorld;
|
|
|
|
impl Extension for HelloWorld {
|
|
fn configure_router(&self, router: Router) -> Router {
|
|
router.route("/", web::get(hello_world))
|
|
}
|
|
}
|
|
|
|
async fn hello_world(request: HttpRequest) -> Result<Markup, ErrorPage> {
|
|
Page::new(request)
|
|
.with_child(Html::with(|_| {
|
|
html! {
|
|
h1 style="text-align: center;" { "Hello World!" }
|
|
}
|
|
}))
|
|
.render()
|
|
}
|
|
|
|
#[pagetop::main]
|
|
async fn main() -> std::io::Result<()> {
|
|
Application::prepare(&HelloWorld).await.run().await
|
|
}
|