Debian Codegraph @

src/ar/error.rs

raw symbols SCIP
1 //! Basic error handling macros to remove boilerplate - not for public export
2
3 /// Simple macro to produce an error in the format this crate typically produces
4 ///
5 /// This is a simplification on `io::Error`
6 #[macro_export]
7 #[doc(hidden)]
8 macro_rules! errrust-analyzer cargo implib 0.3.3 ar/error/err! {
9 ($fmt: expr, $($arg:tt)*) => ( std::io::Error::new(std::io::ErrorKind::InvalidInput, format!($fmt, $($arg)*)) );
10 ($msg: literal) => ( Error::new(ErrorKind::InvalidInput, $msg) );
11 }
12
13 /// Macro to check a precondition, and if the invariant does not hold return an error
14 #[macro_export]
15 #[doc(hidden)]
16 macro_rules! ensurerust-analyzer cargo implib 0.3.3 ar/error/ensure! {
17 ($expr: expr, $msg: literal $(,)?) => ( if !$expr { bail!($msg); } );
18 ($expr: expr, $fmt: expr, $($arg:tt)*) => ( if !$expr { bail!($fmt, $($arg)*); } );
19 }
20
21 /// Unconditionally return an error
22 #[macro_export]
23 #[doc(hidden)]
24 macro_rules! bailrust-analyzer cargo implib 0.3.3 ar/error/bail! {
25 ($fmt: expr, $($arg:tt)*) => ( return Err(err!($fmt, $($arg)*)) );
26 ($msg: literal) => ( return Err(err!($msg)); );
27 }