Use Ref::filter_map if rustc is later than 1.63 (#2904)

This commit is contained in:
Kaede Hoshikawa 2022-10-19 19:45:27 +09:00 committed by GitHub
parent f8fc8859ee
commit 5f6e094996
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 2 deletions

View File

@ -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]

View File

@ -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 {