mirror of
https://github.com/yewstack/yew.git
synced 2025-12-08 21:26:25 +00:00
Use Ref::filter_map if rustc is later than 1.63 (#2904)
This commit is contained in:
parent
f8fc8859ee
commit
5f6e094996
@ -33,6 +33,7 @@ bincode = { version = "1.3.3", optional = true }
|
||||
serde = { version = "1", features = ["derive"] }
|
||||
tracing = "0.1.36"
|
||||
pin-project = "1.0.11"
|
||||
rustversion = "1"
|
||||
|
||||
[dependencies.web-sys]
|
||||
version = "^0.3.59"
|
||||
@ -84,7 +85,6 @@ tokio-stream = { version = "0.1", features = ["time"], optional = true }
|
||||
wasm-bindgen-test = "0.3"
|
||||
gloo = { version = "0.8", features = ["futures"] }
|
||||
wasm-bindgen-futures = "0.4"
|
||||
rustversion = "1"
|
||||
trybuild = "1"
|
||||
|
||||
[dev-dependencies.web-sys]
|
||||
|
||||
@ -452,11 +452,11 @@ mod feat_csr_ssr {
|
||||
}
|
||||
}
|
||||
|
||||
#[rustversion::before(1.63)]
|
||||
#[inline]
|
||||
pub(super) fn arch_get_component(&self) -> Option<impl Deref<Target = COMP> + '_> {
|
||||
self.state.try_borrow().ok().and_then(|state_ref| {
|
||||
state_ref.as_ref()?;
|
||||
// TODO: Replace unwrap with Ref::filter_map once it becomes stable.
|
||||
Some(Ref::map(state_ref, |state| {
|
||||
state
|
||||
.as_ref()
|
||||
@ -466,6 +466,18 @@ mod feat_csr_ssr {
|
||||
})
|
||||
}
|
||||
|
||||
#[rustversion::since(1.63)]
|
||||
#[inline]
|
||||
pub(super) fn arch_get_component(&self) -> Option<impl Deref<Target = COMP> + '_> {
|
||||
self.state.try_borrow().ok().and_then(|state_ref| {
|
||||
// Ref::filter_map is only available since 1.63
|
||||
Ref::filter_map(state_ref, |state| {
|
||||
state.as_ref().and_then(|m| m.downcast_comp_ref::<COMP>())
|
||||
})
|
||||
.ok()
|
||||
})
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn schedule_update(&self) {
|
||||
scheduler::push_component_update(Box::new(UpdateRunner {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user