@@ -42,6 +42,7 @@ pub struct CustomType {
4242 pub frozen_needs_py : bool ,
4343 pub is_special_base : Option < SpecialBase > ,
4444 pub snake_case_name : String ,
45+ pub doc_str : Option < Vec < String > > ,
4546}
4647
4748pub struct StructBindGenerator {
@@ -153,10 +154,38 @@ impl StructBindGenerator {
153154 let raw_types: Vec < _ > = struct_definition
154155 . split ( '\n' )
155156 . filter_map ( |s| {
156- s. trim_start_matches ( ' ' )
157+ let ( name, raw_type) = s
158+ . trim_start_matches ( ' ' )
157159 . trim_start_matches ( "pub " )
158160 . trim_end_matches ( ',' )
159- . split_once ( ": " )
161+ . split_once ( ": " ) ?;
162+
163+ let var_def = format ! ( "pub fn {name}(" ) ;
164+ let var_def_pos = contents. find ( & var_def) . unwrap ( ) ;
165+
166+ let mut docs = Vec :: new ( ) ;
167+
168+ for line in contents[ ..var_def_pos] . lines ( ) . rev ( ) . skip ( 2 ) {
169+ let line = line. trim ( ) ;
170+ if line. starts_with ( "///" ) {
171+ docs. push ( line. trim_start_matches ( "///" ) . trim ( ) ) ;
172+ } else {
173+ break ;
174+ }
175+ }
176+
177+ let struct_doc_str = if docs. is_empty ( ) {
178+ None
179+ } else {
180+ Some (
181+ docs. into_iter ( )
182+ . map ( |s| s. to_string ( ) )
183+ . rev ( )
184+ . collect :: < Vec < _ > > ( ) ,
185+ )
186+ } ;
187+
188+ Some ( ( name, raw_type, struct_doc_str) )
160189 } )
161190 . collect ( ) ;
162191
@@ -165,10 +194,10 @@ impl StructBindGenerator {
165194 Some ( custom_types)
166195 }
167196
168- fn raw_types_to_custom ( raw_types : Vec < ( & str , & str ) > ) -> Vec < CustomType > {
197+ fn raw_types_to_custom ( raw_types : Vec < ( & str , & str , Option < Vec < String > > ) > ) -> Vec < CustomType > {
169198 raw_types
170199 . into_iter ( )
171- . map ( |( name, raw_type) | {
200+ . map ( |( name, raw_type, doc_str ) | {
172201 let ( rust_type, inner_type) = if raw_type. starts_with ( "Vec<" ) {
173202 if raw_type == "Vec<u8>" {
174203 ( RustType :: Vec ( InnerVecType :: U8 ) , None )
@@ -266,6 +295,7 @@ impl StructBindGenerator {
266295 frozen_needs_py,
267296 is_special_base,
268297 snake_case_name : String :: new ( ) ,
298+ doc_str,
269299 }
270300 } )
271301 . collect ( )
0 commit comments