@@ -134,7 +134,7 @@ fn main() -> Result<()> {
134
134
// Write the extracted docs to file
135
135
fs:: write ( output_file, serde_json:: to_string_pretty ( & config_docs) ?) ?;
136
136
137
- println ! ( "Successfully extracted documentation to {}" , output_file ) ;
137
+ println ! ( "Successfully extracted documentation to {output_file}" ) ;
138
138
println ! (
139
139
"Found {} structs with documentation" ,
140
140
config_docs. structs. len( )
@@ -183,10 +183,7 @@ fn generate_rustdoc_json(package: &str) -> Result<serde_json::Value> {
183
183
184
184
// Generate rustdoc for additional crates that might contain referenced constants
185
185
for additional_crate in & additional_crates {
186
- let error_msg = format ! (
187
- "Failed to run cargo rustdoc command for {}" ,
188
- additional_crate
189
- ) ;
186
+ let error_msg = format ! ( "Failed to run cargo rustdoc command for {additional_crate}" ) ;
190
187
let output = StdCommand :: new ( "cargo" )
191
188
. args ( [
192
189
"+nightly" ,
@@ -208,10 +205,7 @@ fn generate_rustdoc_json(package: &str) -> Result<serde_json::Value> {
208
205
209
206
if !output. status . success ( ) {
210
207
let stderr = String :: from_utf8_lossy ( & output. stderr ) ;
211
- eprintln ! (
212
- "Warning: Failed to generate rustdoc for {}: {}" ,
213
- additional_crate, stderr
214
- ) ;
208
+ eprintln ! ( "Warning: Failed to generate rustdoc for {additional_crate}: {stderr}" ) ;
215
209
}
216
210
}
217
211
@@ -225,7 +219,7 @@ fn generate_rustdoc_json(package: &str) -> Result<serde_json::Value> {
225
219
} ;
226
220
227
221
// Read the generated JSON file - rustdoc generates it based on library name
228
- let json_file_path = format ! ( "{}/doc/{}.json" , rustdoc_target_dir , lib_name ) ;
222
+ let json_file_path = format ! ( "{rustdoc_target_dir }/doc/{lib_name }.json" ) ;
229
223
let json_content = std:: fs:: read_to_string ( json_file_path)
230
224
. context ( "Failed to read generated rustdoc JSON file" ) ?;
231
225
@@ -249,10 +243,10 @@ fn extract_config_docs_from_rustdoc(
249
243
// Check if this item is a struct by looking for the "struct" field
250
244
if get_json_object ( item, & [ "inner" , "struct" ] ) . is_some ( ) {
251
245
// Check if this struct is in our target list (if specified)
252
- if let Some ( targets) = target_structs {
253
- if !targets. contains ( & name. to_string ( ) ) {
254
- continue ;
255
- }
246
+ if let Some ( targets) = target_structs
247
+ && !targets. contains ( & name. to_string ( ) )
248
+ {
249
+ continue ;
256
250
}
257
251
258
252
let ( struct_doc_opt, referenced_constants) =
@@ -464,8 +458,7 @@ fn parse_field_documentation(
464
458
"" => false , // Empty string defaults to false
465
459
text => text. parse :: < bool > ( ) . unwrap_or_else ( |_| {
466
460
eprintln ! (
467
- "Warning: Invalid @required value '{}' for field '{}', defaulting to false" ,
468
- text, field_name
461
+ "Warning: Invalid @required value '{text}' for field '{field_name}', defaulting to false"
469
462
) ;
470
463
false
471
464
} ) ,
@@ -632,14 +625,14 @@ fn parse_folded_block_scalar(lines: &[&str], _base_indent: usize) -> String {
632
625
// Remove trailing empty lines but preserve a single trailing newline if content exists
633
626
let trimmed = result. trim_end_matches ( '\n' ) ;
634
627
if !trimmed. is_empty ( ) && result. ends_with ( '\n' ) {
635
- format ! ( "{}\n " , trimmed )
628
+ format ! ( "{trimmed }\n " )
636
629
} else {
637
630
trimmed. to_string ( )
638
631
}
639
632
}
640
633
641
634
fn extract_annotation ( metadata_section : & str , annotation_name : & str ) -> Option < String > {
642
- let annotation_pattern = format ! ( "@{}:" , annotation_name ) ;
635
+ let annotation_pattern = format ! ( "@{annotation_name }:" ) ;
643
636
644
637
if let Some ( _start_pos) = metadata_section. find ( & annotation_pattern) {
645
638
// Split the metadata section into lines for processing
@@ -820,15 +813,13 @@ fn resolve_constant_reference(
820
813
let additional_crate_libs = [ "stacks_common" ] ; // Library names for additional crates
821
814
822
815
for lib_name in & additional_crate_libs {
823
- let json_file_path = format ! ( "target/rustdoc-json/doc/{}.json" , lib_name) ;
824
- if let Ok ( json_content) = std:: fs:: read_to_string ( & json_file_path) {
825
- if let Ok ( rustdoc_json) = serde_json:: from_str :: < serde_json:: Value > ( & json_content) {
826
- if let Some ( index) = get_json_object ( & rustdoc_json, & [ "index" ] ) {
827
- if let Some ( value) = resolve_constant_in_index ( name, index) {
828
- return Some ( value) ;
829
- }
830
- }
831
- }
816
+ let json_file_path = format ! ( "target/rustdoc-json/doc/{lib_name}.json" ) ;
817
+ if let Ok ( json_content) = std:: fs:: read_to_string ( & json_file_path)
818
+ && let Ok ( rustdoc_json) = serde_json:: from_str :: < serde_json:: Value > ( & json_content)
819
+ && let Some ( index) = get_json_object ( & rustdoc_json, & [ "index" ] )
820
+ && let Some ( value) = resolve_constant_in_index ( name, index)
821
+ {
822
+ return Some ( value) ;
832
823
}
833
824
}
834
825
@@ -842,61 +833,57 @@ fn resolve_constant_in_index(
842
833
// Look for a constant with the given name in the rustdoc index
843
834
for ( _item_id, item) in rustdoc_index {
844
835
// Check if this item's name matches the constant we're looking for
845
- if let Some ( item_name) = get_json_string ( item, & [ "name" ] ) {
846
- if item_name == name {
847
- // Check if this item is a constant by looking for the "constant" field
848
- if let Some ( constant_data) = get_json_object ( item, & [ "inner" , "constant" ] ) {
849
- // Try newer rustdoc JSON structure first (with nested 'const' field)
850
- let constant_data_value = serde_json:: Value :: Object ( constant_data. clone ( ) ) ;
851
- if get_json_object ( & constant_data_value, & [ "const" ] ) . is_some ( ) {
852
- // For literal constants, prefer expr which doesn't have type suffix
853
- if get_json_path ( & constant_data_value, & [ "const" , "is_literal" ] )
854
- . and_then ( |v| v. as_bool ( ) )
855
- == Some ( true )
856
- {
857
- // Access the expression field for literal constant values
858
- if let Some ( expr) =
859
- get_json_string ( & constant_data_value, & [ "const" , "expr" ] )
860
- {
861
- if expr != "_" {
862
- return Some ( expr. to_string ( ) ) ;
863
- }
864
- }
865
- }
866
-
867
- // For computed constants or when expr is "_", use value but strip type suffix
868
- if let Some ( value) =
869
- get_json_string ( & constant_data_value, & [ "const" , "value" ] )
870
- {
871
- return Some ( strip_type_suffix ( value) ) ;
872
- }
873
-
874
- // Fallback to expr if value is not available
836
+ if let Some ( item_name) = get_json_string ( item, & [ "name" ] )
837
+ && item_name == name
838
+ {
839
+ // Check if this item is a constant by looking for the "constant" field
840
+ if let Some ( constant_data) = get_json_object ( item, & [ "inner" , "constant" ] ) {
841
+ // Try newer rustdoc JSON structure first (with nested 'const' field)
842
+ let constant_data_value = serde_json:: Value :: Object ( constant_data. clone ( ) ) ;
843
+ if get_json_object ( & constant_data_value, & [ "const" ] ) . is_some ( ) {
844
+ // For literal constants, prefer expr which doesn't have type suffix
845
+ if get_json_path ( & constant_data_value, & [ "const" , "is_literal" ] )
846
+ . and_then ( |v| v. as_bool ( ) )
847
+ == Some ( true )
848
+ {
849
+ // Access the expression field for literal constant values
875
850
if let Some ( expr) =
876
851
get_json_string ( & constant_data_value, & [ "const" , "expr" ] )
852
+ && expr != "_"
877
853
{
878
- if expr != "_" {
879
- return Some ( expr. to_string ( ) ) ;
880
- }
854
+ return Some ( expr. to_string ( ) ) ;
881
855
}
882
856
}
883
857
884
- // Fall back to older rustdoc JSON structure for compatibility
885
- if let Some ( value) = get_json_string ( & constant_data_value, & [ "value" ] ) {
858
+ // For computed constants or when expr is "_", use value but strip type suffix
859
+ if let Some ( value) = get_json_string ( & constant_data_value, & [ "const" , "value" ] )
860
+ {
886
861
return Some ( strip_type_suffix ( value) ) ;
887
862
}
888
- if let Some ( expr) = get_json_string ( & constant_data_value, & [ "expr" ] ) {
889
- if expr != "_" {
890
- return Some ( expr. to_string ( ) ) ;
891
- }
892
- }
893
863
894
- // For some constants, the value might be in the type field if it's a simple literal
895
- if let Some ( type_str) = get_json_string ( & constant_data_value, & [ "type" ] ) {
896
- // Handle simple numeric or string literals embedded in type
897
- return Some ( type_str. to_string ( ) ) ;
864
+ // Fallback to expr if value is not available
865
+ if let Some ( expr) = get_json_string ( & constant_data_value, & [ "const" , "expr" ] )
866
+ && expr != "_"
867
+ {
868
+ return Some ( expr. to_string ( ) ) ;
898
869
}
899
870
}
871
+
872
+ // Fall back to older rustdoc JSON structure for compatibility
873
+ if let Some ( value) = get_json_string ( & constant_data_value, & [ "value" ] ) {
874
+ return Some ( strip_type_suffix ( value) ) ;
875
+ }
876
+ if let Some ( expr) = get_json_string ( & constant_data_value, & [ "expr" ] )
877
+ && expr != "_"
878
+ {
879
+ return Some ( expr. to_string ( ) ) ;
880
+ }
881
+
882
+ // For some constants, the value might be in the type field if it's a simple literal
883
+ if let Some ( type_str) = get_json_string ( & constant_data_value, & [ "type" ] ) {
884
+ // Handle simple numeric or string literals embedded in type
885
+ return Some ( type_str. to_string ( ) ) ;
886
+ }
900
887
}
901
888
}
902
889
}
0 commit comments