Replies: 1 comment
-
|
I ended up with this monstrosity which I consider a temporary solution: // usage: deluxe::parse_attributes::<Field, OptionalAttr<FieldAttr>>(field)
#[derive(Debug, Clone)]
pub struct OptionalAttr<R>(pub Option<R>);
impl<'t, R> ParseAttributes<'t, Field> for OptionalAttr<R>
where
R: ParseAttributes<'t, Field>,
{
fn path_matches(path: &syn::Path) -> bool {
R::path_matches(path)
}
fn parse_attributes(src: &'t Field) -> Result<Self> {
let has_attr = src
.attrs()
.iter()
.any(|attr| Self::path_matches(attr.path()));
Ok(if has_attr {
Self(Some(R::parse_attributes(src)?))
} else {
Self(None)
})
}
} |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Let's say I have a struct:
But I'd like to parse Option<FieldAttr> to allow fields with no my_attr at all.
Beta Was this translation helpful? Give feedback.
All reactions