Skip to content

Commit

Permalink
simplify ResultsHook::get() using 'let else'
Browse files Browse the repository at this point in the history
  • Loading branch information
dwrensha committed Sep 3, 2024
1 parent 871e0a9 commit 30356b1
Showing 1 changed file with 22 additions and 29 deletions.
51 changes: 22 additions & 29 deletions capnp-rpc/src/rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2214,36 +2214,29 @@ impl<VatId> Drop for Results<VatId> {
impl<VatId> ResultsHook for Results<VatId> {
fn get(&mut self) -> ::capnp::Result<any_pointer::Builder> {
use ::capnp::traits::ImbueMut;
if let Some(ref mut inner) = self.inner {
inner.ensure_initialized();
match inner.variant {
None => unreachable!(),
Some(ResultsVariant::Rpc(ref mut message, ref mut cap_table)) => {
let root: message::Builder = message.get_body()?.get_as()?;
match root.which()? {
message::Return(ret) => match ret?.which()? {
return_::Results(payload) => {
let mut content = payload?.get_content();
content.imbue_mut(cap_table);
Ok(content)
}
_ => {
unreachable!()
}
},
_ => {
unreachable!()
}
}
}
Some(ResultsVariant::LocallyRedirected(ref mut message, ref mut cap_table)) => {
let mut result: any_pointer::Builder = message.get_root()?;
result.imbue_mut(cap_table);
Ok(result)
}
let Some(ref mut inner) = self.inner else {
unreachable!();
};
inner.ensure_initialized();
match inner.variant {
None => unreachable!(),
Some(ResultsVariant::Rpc(ref mut message, ref mut cap_table)) => {
let root: message::Builder = message.get_body()?.get_as()?;
let message::Return(ret) = root.which()? else {
unreachable!();
};
let return_::Results(payload) = ret?.which()? else {
unreachable!()
};
let mut content = payload?.get_content();
content.imbue_mut(cap_table);
Ok(content)
}
Some(ResultsVariant::LocallyRedirected(ref mut message, ref mut cap_table)) => {
let mut result: any_pointer::Builder = message.get_root()?;
result.imbue_mut(cap_table);
Ok(result)
}
} else {
unreachable!()
}
}

Expand Down

0 comments on commit 30356b1

Please sign in to comment.