From f28633154871a69c68a24b9fcb23ba97badda1d7 Mon Sep 17 00:00:00 2001 From: David Renshaw Date: Mon, 2 Sep 2024 10:18:21 -0400 Subject: [PATCH] simplify via 'let else' --- capnp-rpc/src/rpc.rs | 46 ++++++++++++++++++++------------------------ 1 file changed, 21 insertions(+), 25 deletions(-) diff --git a/capnp-rpc/src/rpc.rs b/capnp-rpc/src/rpc.rs index bc9234c5a..52d7ac103 100644 --- a/capnp-rpc/src/rpc.rs +++ b/capnp-rpc/src/rpc.rs @@ -1481,35 +1481,31 @@ impl ConnectionState { if is_promise { // We need to construct a PromiseClient around this import, if we haven't already. - match state.imports.borrow_mut().slots.get_mut(&import_id) { - Some(import) => { - match &import.app_client { - Some(c) => { - // Use the existing one. - Box::new(c.upgrade().expect("dangling client ref?")) - } - None => { - // Create a promise for this import's resolution. + let mut tmp = state.imports.borrow_mut(); + let Some(import) = tmp.slots.get_mut(&import_id) else { + unreachable!() + }; + match &import.app_client { + Some(c) => { + // Use the existing one. + Box::new(c.upgrade().expect("dangling client ref?")) + } + None => { + // Create a promise for this import's resolution. - let client: Box> = Box::new(import_client.into()); - let client: Box = client; + let client: Box> = Box::new(import_client.into()); + let client: Box = client; - // XXX do I need something like this? - // Make sure the import is not destroyed while this promise exists. - // let promise = promise.attach(client.add_ref()); + // XXX do I need something like this? + // Make sure the import is not destroyed while this promise exists. + // let promise = promise.attach(client.add_ref()); - let client = - PromiseClient::new(&connection_state, client, Some(import_id)); + let client = PromiseClient::new(&connection_state, client, Some(import_id)); - import.promise_client_to_resolve = Some(Rc::downgrade(&client)); - let client: Box> = Box::new(client.into()); - import.app_client = Some(client.downgrade()); - client - } - } - } - None => { - unreachable!() + import.promise_client_to_resolve = Some(Rc::downgrade(&client)); + let client: Box> = Box::new(client.into()); + import.app_client = Some(client.downgrade()); + client } } } else {