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.
45use anyhow::format_err;
6use std::fmt::Display;
78pub trait SendResultExt<T>: Sized {
9fn format_send_err(self) -> Result<T, anyhow::Error>;
1011fn format_send_err_with_context<C>(self, context: C) -> Result<T, anyhow::Error>
12where
13C: Display;
14}
1516impl<T> SendResultExt<T> for Result<T, fidl::Error> {
17fn format_send_err(self) -> Result<T, anyhow::Error> {
18self.map_err(|error| format_err!("Failed to respond: {}", error))
19 }
2021fn format_send_err_with_context<C>(self, context: C) -> Result<T, anyhow::Error>
22where
23C: Display,
24 {
25self.map_err(|error| format_err!("Failed to respond ({}): {}", context, error))
26 }
27}