fidl_fuchsia_net_stack_ext/
error.rs
1use anyhow::Context as _;
6
7use fidl_fuchsia_net_stack as fidl_net_stack;
8
9#[macro_export]
10macro_rules! exec_fidl {
11 ($method:expr, $context:expr) => {
12 $method.await.squash_result().context($context)
13 };
14}
15
16pub struct NetstackError(pub fidl_net_stack::Error);
19
20impl std::fmt::Debug for NetstackError {
21 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
22 std::fmt::Debug::fmt(&self.0, f)
23 }
24}
25
26impl std::fmt::Display for NetstackError {
27 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
28 std::fmt::Debug::fmt(self, f)
29 }
30}
31
32impl std::error::Error for NetstackError {}
33
34pub trait FidlReturn {
36 type Item;
37 fn squash_result(self) -> Result<Self::Item, anyhow::Error>;
38}
39
40impl<T> FidlReturn for Result<Result<T, fidl_net_stack::Error>, fidl::Error> {
41 type Item = T;
42
43 fn squash_result(self) -> Result<Self::Item, anyhow::Error> {
44 Ok(self.context("FIDL error")?.map_err(NetstackError).context("Netstack error")?)
45 }
46}