docs.rs 827 B

12345678910111213141516171819202122232425262728
  1. use syn::{Lit::Str, Meta::NameValue};
  2. // returns vec of doc strings
  3. pub fn parse(attrs: &[syn::Attribute]) -> Option<Vec<String>> {
  4. let doc_strings: Vec<String> = attrs
  5. .iter()
  6. .filter_map(|attr| match attr.parse_meta() {
  7. Ok(NameValue(meta)) => {
  8. if meta.path.is_ident("doc") {
  9. if let Str(doc) = meta.lit {
  10. let val = doc.value().trim().to_string();
  11. if val.starts_with("CHECK:") {
  12. return None;
  13. }
  14. return Some(val);
  15. }
  16. }
  17. None
  18. }
  19. _ => None,
  20. })
  21. .collect();
  22. if doc_strings.is_empty() {
  23. None
  24. } else {
  25. Some(doc_strings)
  26. }
  27. }