aboutsummaryrefslogtreecommitdiff
path: root/macros/src/macro_flag.rs
diff options
context:
space:
mode:
authorHampusM <hampus@hampusmat.com>2023-01-30 21:29:21 +0100
committerHampusM <hampus@hampusmat.com>2023-01-30 21:29:21 +0100
commit178267c701c233542078c09fe6b19802f9642dbd (patch)
tree3d3010806f6509c062ca86dbbbe9c3a6cd2fe547 /macros/src/macro_flag.rs
parent17ca46e95af38a914197958bbcc1e759865b6005 (diff)
feat: improve macro error messages
Diffstat (limited to 'macros/src/macro_flag.rs')
-rw-r--r--macros/src/macro_flag.rs43
1 files changed, 37 insertions, 6 deletions
diff --git a/macros/src/macro_flag.rs b/macros/src/macro_flag.rs
index 97a8ff2..f0e3a70 100644
--- a/macros/src/macro_flag.rs
+++ b/macros/src/macro_flag.rs
@@ -1,22 +1,37 @@
+use std::hash::Hash;
+
+use proc_macro2::Span;
use syn::parse::{Parse, ParseStream};
use syn::{Ident, LitBool, Token};
-#[derive(Debug, PartialEq, Eq)]
+#[derive(Debug, Eq, Clone)]
pub struct MacroFlag
{
pub flag: Ident,
pub is_on: LitBool,
}
-impl Parse for MacroFlag
+impl MacroFlag
{
- fn parse(input: ParseStream) -> syn::Result<Self>
+ pub fn new_off(flag: &str) -> Self
{
- let input_forked = input.fork();
+ Self {
+ flag: Ident::new(flag, Span::call_site()),
+ is_on: LitBool::new(false, Span::call_site()),
+ }
+ }
- let flag: Ident = input_forked.parse()?;
+ pub fn is_on(&self) -> bool
+ {
+ self.is_on.value
+ }
+}
- input.parse::<Ident>()?;
+impl Parse for MacroFlag
+{
+ fn parse(input: ParseStream) -> syn::Result<Self>
+ {
+ let flag = input.parse::<Ident>()?;
input.parse::<Token![=]>()?;
@@ -26,6 +41,22 @@ impl Parse for MacroFlag
}
}
+impl PartialEq for MacroFlag
+{
+ fn eq(&self, other: &Self) -> bool
+ {
+ self.flag == other.flag
+ }
+}
+
+impl Hash for MacroFlag
+{
+ fn hash<H: std::hash::Hasher>(&self, state: &mut H)
+ {
+ self.flag.hash(state);
+ }
+}
+
#[cfg(test)]
mod tests
{