Skip to content

Commit 31ffdab

Browse files
AudaciousAxiomogoffart
authored andcommitted
refactor: simplify the feature documentation generation
This makes the default feature label more explicit, and factors out some formatting operations to only use one `write!` statement, making the generation easier to maintain and expand.
1 parent 5237eed commit 31ffdab

File tree

1 file changed

+15
-20
lines changed

1 file changed

+15
-20
lines changed

lib.rs

Lines changed: 15 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -503,27 +503,22 @@ fn process_toml(cargo_toml: &str, args: &Args) -> Result<String, String> {
503503
let mut result = String::new();
504504
for (f, top, comment) in features {
505505
let default = if default_features.contains(f) { " *(enabled by default)*" } else { "" };
506-
if !comment.trim().is_empty() {
507-
if let Some(feature_label) = &args.feature_label {
508-
writeln!(
509-
result,
510-
"{}* {}{} —{}",
511-
top,
512-
feature_label.replace("{feature}", f),
513-
default,
514-
comment.trim_end(),
515-
)
516-
.unwrap();
517-
} else {
518-
writeln!(result, "{}* **`{}`**{} —{}", top, f, default, comment.trim_end())
519-
.unwrap();
520-
}
521-
} else if let Some(feature_label) = &args.feature_label {
522-
writeln!(result, "{}* {}{}", top, feature_label.replace("{feature}", f), default,)
523-
.unwrap();
506+
let feature_label = args.feature_label.as_deref().unwrap_or("**`{feature}`**");
507+
let comment = if comment.trim().is_empty() {
508+
String::new()
524509
} else {
525-
writeln!(result, "{}* **`{}`**{}", top, f, default).unwrap();
526-
}
510+
format!(" —{}", comment.trim_end())
511+
};
512+
513+
writeln!(
514+
result,
515+
"{}* {}{}{}",
516+
top,
517+
feature_label.replace("{feature}", f),
518+
default,
519+
comment,
520+
)
521+
.unwrap();
527522
}
528523
result += &top_comment;
529524
Ok(result)

0 commit comments

Comments
 (0)