Skip to main content

anchor_syn/parser/
docs.rs

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