Get the attribute matching needle name.
(
needle: &'a str,
attributes: &'a [syn::Attribute],
)
| 246 | |
| 247 | /// Get the attribute matching needle name. |
| 248 | pub fn get_attribute<'a>( |
| 249 | needle: &'a str, |
| 250 | attributes: &'a [syn::Attribute], |
| 251 | ) -> Option<&'a syn::Attribute> { |
| 252 | // if multiple attributes pass the conditions |
| 253 | // we still want to return the last |
| 254 | attributes |
| 255 | .iter() |
| 256 | // Reverse the iterator to check the last attribute first. |
| 257 | .rev() |
| 258 | // From the `find` documentation: |
| 259 | // "find() is short-circuiting; |
| 260 | // in other words, it will stop processing as soon as the closure returns true." |
| 261 | .find(|attr| { |
| 262 | // Checks if any segments in the iterator equal `needle`. Returns |
| 263 | // true if a match is found, otherwise false. |
| 264 | attr.meta |
| 265 | .path() |
| 266 | .segments |
| 267 | .iter() |
| 268 | .any(|segment| segment.ident == needle) |
| 269 | }) |
| 270 | } |
| 271 | |
| 272 | pub(crate) fn parse_serde_case( |
| 273 | val: impl Into<Option<String>>, |