mirror of
https://github.com/yewstack/yew.git
synced 2025-12-08 21:26:25 +00:00
Only rewrite async closure for rust version before 1.85.0 (#3831)
* use_prepared_state with unit type is unlikely usage --------- Co-authored-by: Matt "Siyuan" Yan <mattsy1999@gmail.com>
This commit is contained in:
parent
e5b2cf3611
commit
4a28de483a
@ -22,10 +22,10 @@ quote = "1"
|
|||||||
syn = { version = "2", features = ["full", "extra-traits", "visit-mut"] }
|
syn = { version = "2", features = ["full", "extra-traits", "visit-mut"] }
|
||||||
once_cell = "1"
|
once_cell = "1"
|
||||||
prettyplease = "0.2"
|
prettyplease = "0.2"
|
||||||
|
rustversion = "1"
|
||||||
|
|
||||||
# testing
|
# testing
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
rustversion = "1"
|
|
||||||
trybuild = "1"
|
trybuild = "1"
|
||||||
yew = { path = "../yew" }
|
yew = { path = "../yew" }
|
||||||
|
|
||||||
|
|||||||
@ -58,8 +58,8 @@ impl Parse for PreparedState {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl PreparedState {
|
impl PreparedState {
|
||||||
// Async closure is not stable, so we rewrite it to closure + async block
|
// Async closure was not stable, so we rewrite it to closure + async block
|
||||||
#[cfg(not(nightly_yew))]
|
#[rustversion::before(1.85)]
|
||||||
pub fn rewrite_to_closure_with_async_block(&self) -> ExprClosure {
|
pub fn rewrite_to_closure_with_async_block(&self) -> ExprClosure {
|
||||||
use proc_macro2::Span;
|
use proc_macro2::Span;
|
||||||
use syn::parse_quote;
|
use syn::parse_quote;
|
||||||
@ -95,7 +95,7 @@ impl PreparedState {
|
|||||||
closure
|
closure
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(nightly_yew)]
|
#[rustversion::since(1.85)]
|
||||||
pub fn rewrite_to_closure_with_async_block(&self) -> ExprClosure {
|
pub fn rewrite_to_closure_with_async_block(&self) -> ExprClosure {
|
||||||
self.closure.clone()
|
self.closure.clone()
|
||||||
}
|
}
|
||||||
|
|||||||
@ -47,7 +47,7 @@ pub use feat_ssr::*;
|
|||||||
/// # { todo!() }
|
/// # { todo!() }
|
||||||
/// ```
|
/// ```
|
||||||
///
|
///
|
||||||
/// The first argument can also be an [async closure](https://github.com/rust-lang/rust/issues/62290).
|
/// The first argument can also be an async closure
|
||||||
///
|
///
|
||||||
/// `let state = use_prepared_state!(async |deps| -> ReturnType { ... }, deps)?;`
|
/// `let state = use_prepared_state!(async |deps| -> ReturnType { ... }, deps)?;`
|
||||||
///
|
///
|
||||||
@ -85,10 +85,6 @@ pub use feat_ssr::*;
|
|||||||
/// You MUST denote the return type of the closure with `|deps| -> ReturnType { ... }`. This
|
/// You MUST denote the return type of the closure with `|deps| -> ReturnType { ... }`. This
|
||||||
/// type is used during client side rendering to deserialize the state prepared on the server
|
/// type is used during client side rendering to deserialize the state prepared on the server
|
||||||
/// side.
|
/// side.
|
||||||
///
|
|
||||||
/// Whilst async closure is an unstable feature, the procedural macro will rewrite this to a
|
|
||||||
/// closure that returns an async block automatically. You can use this hook with async closure
|
|
||||||
/// in stable Rust.
|
|
||||||
pub use use_prepared_state_macro as use_prepared_state;
|
pub use use_prepared_state_macro as use_prepared_state;
|
||||||
// With SSR.
|
// With SSR.
|
||||||
#[doc(hidden)]
|
#[doc(hidden)]
|
||||||
|
|||||||
@ -141,8 +141,9 @@ async fn bench_concurrent_task() -> Duration {
|
|||||||
|
|
||||||
#[function_component]
|
#[function_component]
|
||||||
fn Comp() -> HtmlResult {
|
fn Comp() -> HtmlResult {
|
||||||
let _state = use_prepared_state!((), async move |_| -> () {
|
let _state = use_prepared_state!((), async move |_| -> usize {
|
||||||
sleep(Duration::from_secs(1)).await;
|
sleep(Duration::from_secs(1)).await;
|
||||||
|
42
|
||||||
})?;
|
})?;
|
||||||
|
|
||||||
Ok(Html::default())
|
Ok(Html::default())
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user