macro_rules! find_attr {
($attributes_list:expr, $pattern:pat $(if $guard:expr)?) => { ... };
($attributes_list:expr, $pattern:pat $(if $guard:expr)? => $e:expr) => { ... };
}
Expand description
Finds attributes in sequences of attributes by pattern matching.
A little like matches
but for attributes.
ⓘ
// finds the repr attribute
if let Some(r) = find_attr!(attrs, AttributeKind::Repr(r) => r) {
}
// checks if one has matched
if find_attr!(attrs, AttributeKind::Repr(_)) {
}
Often this requires you to first end up with a list of attributes.
A common way to get those is through tcx.get_all_attrs(did)