File tree 1 file changed +24
-5
lines changed
1 file changed +24
-5
lines changed Original file line number Diff line number Diff line change @@ -24,12 +24,31 @@ pub fn docs(attrs: &[Attribute]) -> impl Iterator<Item = &Attribute> {
24
24
attrs. iter ( ) . filter ( |a| is_doc ( a) )
25
25
}
26
26
27
+ /// Flattens all the `#[doc = "..."]` attributes into a single string.
27
28
pub fn docs_str ( attrs : & [ Attribute ] ) -> String {
28
- docs ( attrs)
29
- . filter_map ( |attr| attr. parse_args :: < LitStr > ( ) . ok ( ) )
30
- . map ( |doc| doc. value ( ) )
31
- . collect :: < Vec < _ > > ( )
32
- . join ( "\n " )
29
+ let mut doc = String :: new ( ) ;
30
+ for attr in docs ( attrs) {
31
+ let syn:: Meta :: NameValue ( syn:: MetaNameValue {
32
+ value :
33
+ syn:: Expr :: Lit ( syn:: ExprLit {
34
+ lit : syn:: Lit :: Str ( s) ,
35
+ ..
36
+ } ) ,
37
+ ..
38
+ } ) = & attr. meta
39
+ else {
40
+ continue
41
+ } ;
42
+
43
+ let value = s. value ( ) ;
44
+ if !value. is_empty ( ) {
45
+ if !doc. is_empty ( ) {
46
+ doc. push ( '\n' ) ;
47
+ }
48
+ doc. push_str ( & value) ;
49
+ }
50
+ }
51
+ doc
33
52
}
34
53
35
54
pub fn derives ( attrs : & [ Attribute ] ) -> impl Iterator < Item = & Attribute > {
You can’t perform that action at this time.
0 commit comments