Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 1 commit into from Oct 19, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/yew/Cargo.toml
Expand Up @@ -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"
Expand Down Expand Up @@ -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]
Expand Down
14 changes: 13 additions & 1 deletion packages/yew/src/html/component/scope.rs
Expand Up @@ -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()
Expand All @@ -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 {
Expand Down