1
1
use std:: collections:: BTreeMap ;
2
2
3
3
use k8s_version:: Version ;
4
- use proc_macro2:: Span ;
5
- use quote:: format_ident;
4
+ use proc_macro2:: { Span , TokenStream } ;
5
+ use quote:: { format_ident, quote , ToTokens } ;
6
6
use syn:: Ident ;
7
7
8
8
use crate :: {
@@ -34,24 +34,7 @@ pub(crate) struct ContainerVersion {
34
34
pub ( crate ) ident : Ident ,
35
35
36
36
/// Store additional doc-comment lines for this version.
37
- pub ( crate ) version_specific_docs : Vec < String > ,
38
- }
39
-
40
- /// Converts lines of doc-comments into a trimmed list.
41
- fn process_docs ( input : & Option < String > ) -> Vec < String > {
42
- if let Some ( input) = input {
43
- input
44
- // Trim the leading and trailing whitespace, deleting suprefluous
45
- // empty lines.
46
- . trim ( )
47
- . lines ( )
48
- // Trim the leading and trailing whitespace on each line that can be
49
- // introduced when the developer indents multi-line comments.
50
- . map ( |line| line. trim ( ) . to_owned ( ) )
51
- . collect ( )
52
- } else {
53
- Vec :: new ( )
54
- }
37
+ pub ( crate ) docs : Docs ,
55
38
}
56
39
57
40
impl From < & ContainerAttributes > for Vec < ContainerVersion > {
@@ -63,13 +46,55 @@ impl From<&ContainerAttributes> for Vec<ContainerVersion> {
63
46
skip_from : v. skip . as_ref ( ) . map_or ( false , |s| s. from . is_present ( ) ) ,
64
47
ident : Ident :: new ( & v. name . to_string ( ) , Span :: call_site ( ) ) ,
65
48
deprecated : v. deprecated . is_present ( ) ,
49
+ docs : v. doc . clone ( ) . into ( ) ,
66
50
inner : v. name ,
67
- version_specific_docs : process_docs ( & v. doc ) ,
68
51
} )
69
52
. collect ( )
70
53
}
71
54
}
72
55
56
+ #[ derive( Clone , Debug ) ]
57
+ pub ( crate ) struct Docs ( Vec < String > ) ;
58
+
59
+ impl From < Option < String > > for Docs {
60
+ fn from ( doc : Option < String > ) -> Self {
61
+ let lines = if let Some ( doc) = doc {
62
+ doc
63
+ // Trim the leading and trailing whitespace, deleting
64
+ // superfluous empty lines.
65
+ . trim ( )
66
+ . lines ( )
67
+ // Trim the leading and trailing whitespace on each line that
68
+ // can be introduced when the developer indents multi-line
69
+ // comments.
70
+ . map ( |line| line. trim ( ) . into ( ) )
71
+ . collect ( )
72
+ } else {
73
+ Vec :: new ( )
74
+ } ;
75
+
76
+ Self ( lines)
77
+ }
78
+ }
79
+
80
+ impl ToTokens for Docs {
81
+ fn to_tokens ( & self , tokens : & mut TokenStream ) {
82
+ for ( index, line) in self . 0 . iter ( ) . enumerate ( ) {
83
+ if index == 0 {
84
+ // Prepend an empty line to clearly separate the version/action
85
+ // specific docs.
86
+ tokens. extend ( quote ! {
87
+ #[ doc = "" ]
88
+ } )
89
+ }
90
+
91
+ tokens. extend ( quote ! {
92
+ #[ doc = #line]
93
+ } )
94
+ }
95
+ }
96
+ }
97
+
73
98
/// Removes the deprecated prefix from a field ident.
74
99
///
75
100
/// See [`DEPRECATED_FIELD_PREFIX`].
0 commit comments