mirror of https://github.com/zkat/miette.git
Adjust `miette!` a little bit
This commit is contained in:
parent
8aaba9974e
commit
021eb01feb
|
|
@ -130,8 +130,7 @@ macro_rules! ensure {
|
||||||
/// string with arguments. It also can take any custom type which implements
|
/// string with arguments. It also can take any custom type which implements
|
||||||
/// `Debug` and `Display`.
|
/// `Debug` and `Display`.
|
||||||
///
|
///
|
||||||
/// # Example
|
/// # Examples
|
||||||
///
|
|
||||||
/// ```
|
/// ```
|
||||||
/// # type V = ();
|
/// # type V = ();
|
||||||
/// #
|
/// #
|
||||||
|
|
@ -146,6 +145,11 @@ macro_rules! ensure {
|
||||||
/// # Ok(())
|
/// # Ok(())
|
||||||
/// }
|
/// }
|
||||||
/// ```
|
/// ```
|
||||||
|
/// ```
|
||||||
|
/// use miette::miette;
|
||||||
|
///
|
||||||
|
/// let err = miette!("expected '('", code = "expected::lparen");
|
||||||
|
/// ```
|
||||||
///
|
///
|
||||||
/// ## `anyhow`/`eyre` Users
|
/// ## `anyhow`/`eyre` Users
|
||||||
///
|
///
|
||||||
|
|
@ -162,6 +166,12 @@ macro_rules! miette {
|
||||||
let error = $err;
|
let error = $err;
|
||||||
(&error).miette_kind().new(error)
|
(&error).miette_kind().new(error)
|
||||||
});
|
});
|
||||||
|
($msg:literal, $(code = $code:literal)? ) => {
|
||||||
|
$crate::Report::from(
|
||||||
|
$crate::MietteDiagnostic::new($msg)
|
||||||
|
$(.with_code($code))?
|
||||||
|
)
|
||||||
|
};
|
||||||
($fmt:expr, $($arg:tt)*) => {
|
($fmt:expr, $($arg:tt)*) => {
|
||||||
$crate::private::new_adhoc(format!($fmt, $($arg)*))
|
$crate::private::new_adhoc(format!($fmt, $($arg)*))
|
||||||
};
|
};
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue