-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathutils.rs
More file actions
38 lines (32 loc) · 1.04 KB
/
utils.rs
File metadata and controls
38 lines (32 loc) · 1.04 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
use syn::{Attribute, Error, Lit, LitBool, Path, Result, spanned::Spanned};
pub fn get_attributes(attrs: &[Attribute]) -> Result<Vec<(Path, Lit)>> {
let mut attributes = Vec::new();
for attribute in attrs {
if !attribute.path().is_ident("table") {
continue;
}
if attribute
.parse_nested_meta(|meta| {
let path = meta.path.clone();
let lit = meta
.value()
.ok()
.map(|v| v.parse())
.transpose()?
.unwrap_or(Lit::from(LitBool {
value: true,
span: path.span(),
}));
attributes.push((path, lit));
Ok(())
})
.is_err()
{
return Err(Error::new_spanned(
attribute,
"Attributes should be of type: #[table(key = \"value\", ..)] or #[table(bool)]",
));
}
}
Ok(attributes)
}