`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`.
27 lines
642 B
Rust
27 lines
642 B
Rust
use pagetop::prelude::*;
|
|
|
|
struct HelloName;
|
|
|
|
impl Extension for HelloName {
|
|
fn configure_router(&self, router: Router) -> Router {
|
|
router.route("/hello/{name}", web::get(hello_name))
|
|
}
|
|
}
|
|
|
|
async fn hello_name(
|
|
request: HttpRequest,
|
|
web::Path(name): web::Path<String>,
|
|
) -> Result<Markup, ErrorPage> {
|
|
Page::new(request)
|
|
.with_child(Html::with(move |_| {
|
|
html! {
|
|
h1 style="text-align: center;" { "Hello " (name) "!" }
|
|
}
|
|
}))
|
|
.render()
|
|
}
|
|
|
|
#[pagetop::main]
|
|
async fn main() -> std::io::Result<()> {
|
|
Application::prepare(&HelloName).await.run().await
|
|
}
|