wlan_fidl_ext/
send_result_ext.rs

1// Copyright 2024 The Fuchsia Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5use anyhow::format_err;
6use std::fmt::Display;
7
8pub trait SendResultExt<T>: Sized {
9    fn format_send_err(self) -> Result<T, anyhow::Error>;
10
11    fn format_send_err_with_context<C>(self, context: C) -> Result<T, anyhow::Error>
12    where
13        C: Display;
14}
15
16impl<T> SendResultExt<T> for Result<T, fidl::Error> {
17    fn format_send_err(self) -> Result<T, anyhow::Error> {
18        self.map_err(|error| format_err!("Failed to respond: {}", error))
19    }
20
21    fn format_send_err_with_context<C>(self, context: C) -> Result<T, anyhow::Error>
22    where
23        C: Display,
24    {
25        self.map_err(|error| format_err!("Failed to respond ({}): {}", context, error))
26    }
27}