1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
pub fn extract_docs(attrs: &[syn::Attribute]) -> Vec<String> {
    attrs
        .iter()
        .filter_map(|attr| {
            match &attr.meta {
                syn::Meta::NameValue(nv) => {
                    // Doc omments are transformed into the form of `#[doc =
                    // r"comment"]` before macros are expanded.
                    // cf., https://docs.rs/syn/latest/syn/struct.Attribute.html#doc-comments
                    if nv.path.is_ident("doc") {
                        match &nv.value {
                            syn::Expr::Lit(syn::ExprLit {
                                lit: syn::Lit::Str(doc),
                                ..
                            }) => Some(doc.value()),
                            _ => None,
                        }
                    } else {
                        None
                    }
                }
                _ => None,
            }
        })
        .collect()
}