structmeta/
arg_types.rs

1use proc_macro2::Span;
2/// `name` style attribute argument.
3///
4/// See [`#[derive(StructMeta)]`](macro@crate::StructMeta) documentation for details.
5#[derive(Clone, Debug, Default)]
6pub struct Flag {
7    pub span: Option<Span>,
8}
9impl Flag {
10    pub const NONE: Flag = Flag { span: None };
11    pub fn value(&self) -> bool {
12        self.span.is_some()
13    }
14}
15impl PartialEq for Flag {
16    fn eq(&self, other: &Self) -> bool {
17        self.value() == other.value()
18    }
19}
20impl From<bool> for Flag {
21    fn from(value: bool) -> Self {
22        Self {
23            span: if value { Some(Span::call_site()) } else { None },
24        }
25    }
26}
27
28/// `name = value` style attribute argument.
29///
30/// See [`#[derive(StructMeta)]`](macro@crate::StructMeta) documentation for details.
31#[derive(Copy, Clone, Debug)]
32pub struct NameValue<T> {
33    pub name_span: Span,
34    pub value: T,
35}
36impl<T: PartialEq> PartialEq for NameValue<T> {
37    fn eq(&self, other: &Self) -> bool {
38        self.value == other.value
39    }
40}
41
42/// `name(value)` style attribute argument.
43///
44/// See [`#[derive(StructMeta)]`](macro@crate::StructMeta) documentation for details.
45#[derive(Copy, Clone, Debug)]
46pub struct NameArgs<T> {
47    pub name_span: Span,
48    pub args: T,
49}
50impl<T: PartialEq> PartialEq for NameArgs<T> {
51    fn eq(&self, other: &Self) -> bool {
52        self.args == other.args
53    }
54}