Skip to content

Commit afe3dcd

Browse files
committed
Use retain_mut in CommentBlock::extract
1 parent d689fd3 commit afe3dcd

File tree

1 file changed

+12
-14
lines changed

1 file changed

+12
-14
lines changed

crates/sourcegen/src/lib.rs

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -58,21 +58,19 @@ impl CommentBlock {
5858
assert!(tag.starts_with(char::is_uppercase));
5959

6060
let tag = format!("{tag}:");
61-
// Would be nice if we had `.retain_mut` here!
62-
CommentBlock::extract_untagged(text)
63-
.into_iter()
64-
.filter_map(|mut block| {
65-
let first = block.contents.remove(0);
66-
first.strip_prefix(&tag).map(|id| {
67-
if block.is_doc {
68-
panic!("Use plain (non-doc) comments with tags like {tag}:\n {first}");
69-
}
61+
let mut blocks = CommentBlock::extract_untagged(text);
62+
blocks.retain_mut(|block| {
63+
let first = block.contents.remove(0);
64+
let Some(id) = first.strip_prefix(&tag) else { return false; };
65+
66+
if block.is_doc {
67+
panic!("Use plain (non-doc) comments with tags like {tag}:\n {first}");
68+
}
7069

71-
block.id = id.trim().to_string();
72-
block
73-
})
74-
})
75-
.collect()
70+
block.id = id.trim().to_string();
71+
true
72+
});
73+
blocks
7674
}
7775

7876
pub fn extract_untagged(text: &str) -> Vec<CommentBlock> {

0 commit comments

Comments
 (0)