From 1adeba311e09d185792174d6fe7506e74e93a986 Mon Sep 17 00:00:00 2001 From: mahmoud-eltahawy Date: Fri, 5 Apr 2024 16:40:52 +0200 Subject: [PATCH] stable ssr_modes_example example --- examples/ssr_modes_axum/rust-toolchain.toml | 2 +- examples/ssr_modes_axum/src/app.rs | 16 ++++++++++------ examples/ssr_modes_axum/src/lib.rs | 2 -- 3 files changed, 11 insertions(+), 9 deletions(-) diff --git a/examples/ssr_modes_axum/rust-toolchain.toml b/examples/ssr_modes_axum/rust-toolchain.toml index 99fa95aaaf..292fe499e3 100644 --- a/examples/ssr_modes_axum/rust-toolchain.toml +++ b/examples/ssr_modes_axum/rust-toolchain.toml @@ -1,2 +1,2 @@ [toolchain] -channel = "nightly-2024-03-31" +channel = "stable" diff --git a/examples/ssr_modes_axum/src/app.rs b/examples/ssr_modes_axum/src/app.rs index 1b042d64ff..906c3677ee 100644 --- a/examples/ssr_modes_axum/src/app.rs +++ b/examples/ssr_modes_axum/src/app.rs @@ -80,20 +80,24 @@ fn Post() -> impl IntoView { .map_err(|_| PostError::InvalidId) }) }; - let post = create_resource(id, |id| async move { + let post_resource = create_resource(id, |id| async move { match id { Err(e) => Err(e), Ok(id) => get_post(id) .await .map(|data| data.ok_or(PostError::PostNotFound)) - .map_err(|_| PostError::ServerError) - .flatten(), + .map_err(|_| PostError::ServerError), } }); + let post = move || match post_resource.get() { + Some(Ok(Ok(v))) => Ok(v), + _ => Err(PostError::ServerError), + }; + let post_view = move || { - post.and_then(|post| { - view! { + post().and_then(|post| { + Ok(view! { // render content

{&post.title}

{&post.content}

@@ -103,7 +107,7 @@ fn Post() -> impl IntoView { // when it's first served <Meta name="description" content=post.content.clone()/> - } + }) }) }; diff --git a/examples/ssr_modes_axum/src/lib.rs b/examples/ssr_modes_axum/src/lib.rs index 344da184e1..3bed2f1a1f 100644 --- a/examples/ssr_modes_axum/src/lib.rs +++ b/examples/ssr_modes_axum/src/lib.rs @@ -1,5 +1,3 @@ -#![feature(result_flattening)] - pub mod app; #[cfg(feature = "ssr")]