hex_conservative/
error.rs

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