Skip to content

Commit

Permalink
get_attributes: Since we only match on filestruct, use assert!
Browse files Browse the repository at this point in the history
  • Loading branch information
cdown committed May 30, 2023
1 parent b829b18 commit ec42029
Showing 1 changed file with 25 additions and 25 deletions.
50 changes: 25 additions & 25 deletions filestruct_derive/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,32 +16,32 @@ fn get_attributes(field: &syn::Field) -> Result<FieldAttributes, syn::parse::Err
let mut attrs = FieldAttributes::default();

for attr in &field.attrs {
if attr.path().is_ident("filestruct") {
attr.parse_nested_meta(|meta| {
let value = meta.value();
match meta
.path
.get_ident()
.map_or_else(String::new, |i| i.to_string())
.as_str()
{
"file" => {
let s: LitStr = value?.parse()?;
attrs.filename = Some(s.value());
}
"trim" => {
let b: LitBool = value?.parse()?;
attrs.trim = Some(b.value());
}
"relative_dir" => {
let s: LitStr = value?.parse()?;
attrs.relative_dir = Some(s.value());
}
_ => return Err(meta.error("unsupported attribute")),
assert!(attr.path().is_ident("filestruct"));

attr.parse_nested_meta(|meta| {
let value = meta.value();
match meta
.path
.get_ident()
.map_or_else(String::new, |i| i.to_string())
.as_str()
{
"file" => {
let s: LitStr = value?.parse()?;
attrs.filename = Some(s.value());
}
Ok(())
})?;
}
"trim" => {
let b: LitBool = value?.parse()?;
attrs.trim = Some(b.value());
}
"relative_dir" => {
let s: LitStr = value?.parse()?;
attrs.relative_dir = Some(s.value());
}
_ => return Err(meta.error("unsupported attribute")),
}
Ok(())
})?;
}

Ok(attrs)
Expand Down

0 comments on commit ec42029

Please sign in to comment.