forked from stellar/rs-soroban-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdoc.rs
More file actions
28 lines (26 loc) · 820 Bytes
/
doc.rs
File metadata and controls
28 lines (26 loc) · 820 Bytes
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
27
28
use itertools::Itertools;
use stellar_xdr::next as stellar_xdr;
use stellar_xdr::StringM;
use syn::{Attribute, Expr, ExprLit, Lit, Meta, MetaNameValue};
const DOCS_MAX_LEN: u32 = 1024;
pub fn docs_from_attrs(attrs: &[Attribute]) -> StringM<DOCS_MAX_LEN> {
let mut docs = attrs
.iter()
.filter(|a| a.path().is_ident("doc"))
.filter_map(|a| match &a.meta {
Meta::NameValue(MetaNameValue {
value:
Expr::Lit(ExprLit {
lit: Lit::Str(s), ..
}),
..
}) => Some(s.value()),
_ => None,
})
.map(|s| s.trim().to_string())
.join("\n")
.as_bytes()
.to_vec();
docs.truncate(DOCS_MAX_LEN as usize);
docs.try_into().unwrap()
}