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