-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patherr.rs
More file actions
49 lines (45 loc) · 1.57 KB
/
err.rs
File metadata and controls
49 lines (45 loc) · 1.57 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
//! Taken from `tinyklv`
#[doc(hidden)]
/// A quick way to add enum variants of [`crate::Error`] to the [`crate::Ctxt`]
/// error or [`syn::Error`] by transforming it into a [`str`].
macro_rules! err {
// --------------------------------------------------
// 1+ expr; 1+ literals
// --------------------------------------------------
($variant:ident($($expr:expr),* ; $($litstr:literal),*)) => {
$crate::Error::$variant(
$($expr.to_token_stream().to_string()),*,
$($litstr.to_string()),*
).as_str()
};
// --------------------------------------------------
// 1+ literals
// --------------------------------------------------
($variant:ident($($litstr:literal),*)) => {
$crate::Error::$variant(
$($litstr.to_string()),*
).as_str()
};
// --------------------------------------------------
// 1+ expressions
// --------------------------------------------------
($variant:ident($($expr:expr),*)) => {
$crate::Error::$variant(
$($expr.to_token_stream().to_string()),*
).as_str()
};
// --------------------------------------------------
// @String operator
// --------------------------------------------------
($variant:ident(@String $expr:expr)) => {
$crate::Error::$variant(
$expr
).as_str()
};
// --------------------------------------------------
// no arguments
// --------------------------------------------------
($variant:ident) => {
$crate::Error::$variant.as_str()
};
}