2022-09-05 02:19:28 +00:00
|
|
|
// SPDX-License-Identifier: CC0-1.0
|
|
|
|
|
|
|
|
//! # Error
|
|
|
|
//!
|
|
|
|
//! Error handling macros and helpers.
|
|
|
|
//!
|
|
|
|
|
2022-09-20 15:11:35 +00:00
|
|
|
pub mod input_string;
|
|
|
|
mod parse_error;
|
|
|
|
|
|
|
|
pub use input_string::InputString;
|
|
|
|
|
2022-09-05 02:19:28 +00:00
|
|
|
/// Formats error.
|
|
|
|
///
|
|
|
|
/// If `std` feature is OFF appends error source (delimited by `: `). We do this because
|
|
|
|
/// `e.source()` is only available in std builds, without this macro the error source is lost for
|
|
|
|
/// no-std builds.
|
|
|
|
#[macro_export]
|
|
|
|
macro_rules! write_err {
|
|
|
|
($writer:expr, $string:literal $(, $args:expr)*; $source:expr) => {
|
|
|
|
{
|
|
|
|
#[cfg(feature = "std")]
|
|
|
|
{
|
|
|
|
let _ = &$source; // Prevents clippy warnings.
|
|
|
|
write!($writer, $string $(, $args)*)
|
|
|
|
}
|
|
|
|
#[cfg(not(feature = "std"))]
|
|
|
|
{
|
|
|
|
write!($writer, concat!($string, ": {}") $(, $args)*, $source)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|