bitcoin_private/error.rs
1// Written by the Rust Bitcoin developers.
2// SPDX-License-Identifier: CC0-1.0
3
4//! # Error
5//!
6//! Error handling macros and helpers.
7//!
8
9/// Formats error.
10///
11/// If `std` feature is OFF appends error source (delimited by `: `). We do this because
12/// `e.source()` is only available in std builds, without this macro the error source is lost for
13/// no-std builds.
14#[macro_export]
15macro_rules! write_err {
16 ($writer:expr, $string:literal $(, $args:expr)*; $source:expr) => {
17 {
18 #[cfg(feature = "std")]
19 {
20 let _ = &$source; // Prevents clippy warnings.
21 write!($writer, $string $(, $args)*)
22 }
23 #[cfg(not(feature = "std"))]
24 {
25 write!($writer, concat!($string, ": {}") $(, $args)*, $source)
26 }
27 }
28 }
29}