Macro pliron::input_error
source ยท macro_rules! input_error { ($loc: expr, $($t:tt)*) => { ... }; }
Expand description
Create ErrorKind::InvalidInput Error from any std::error::Error object. To create Result, use input_err! instead. The macro also accepts format! like arguments to create one-off errors.
use thiserror::Error;
use pliron::{input_error, result::{Result, ErrorKind, Error}, location::Location};
#[derive(Error, Debug)]
#[error("sample error")]
pub struct SampleErr;
assert!(
matches!(
input_error!(Location::Unknown, SampleErr),
Error {
kind: ErrorKind::InvalidInput,
err,
loc: _,
} if err.is::<SampleErr>()
));
let res_msg: Error = input_error!(Location::Unknown, "Some formatted {}", 0);
assert_eq!(
res_msg.err.to_string(),
"Some formatted 0"
);