diff options
| author | DropDemBits <r3usrlnd@gmail.com> | 2023-03-31 17:41:40 -0400 |
|---|---|---|
| committer | DropDemBits <r3usrlnd@gmail.com> | 2023-03-31 17:41:40 -0400 |
| commit | afe3dcd3ff6a5d64fc27311c2768070300c055d1 (patch) | |
| tree | ee13726b6215b1a793a177fd7fb00a65fdb2151f /crates/sourcegen | |
| parent | d689fd30bc8be66bda9b9a2d787bbc236a1ba587 (diff) | |
| download | rust-afe3dcd3ff6a5d64fc27311c2768070300c055d1.tar.gz rust-afe3dcd3ff6a5d64fc27311c2768070300c055d1.zip | |
Use `retain_mut` in `CommentBlock::extract`
Diffstat (limited to 'crates/sourcegen')
| -rw-r--r-- | crates/sourcegen/src/lib.rs | 26 |
1 files changed, 12 insertions, 14 deletions
diff --git a/crates/sourcegen/src/lib.rs b/crates/sourcegen/src/lib.rs index 72d26635c33..c5da6ceb4d1 100644 --- a/crates/sourcegen/src/lib.rs +++ b/crates/sourcegen/src/lib.rs @@ -58,21 +58,19 @@ impl CommentBlock { assert!(tag.starts_with(char::is_uppercase)); let tag = format!("{tag}:"); - // Would be nice if we had `.retain_mut` here! - CommentBlock::extract_untagged(text) - .into_iter() - .filter_map(|mut block| { - let first = block.contents.remove(0); - first.strip_prefix(&tag).map(|id| { - if block.is_doc { - panic!("Use plain (non-doc) comments with tags like {tag}:\n {first}"); - } + let mut blocks = CommentBlock::extract_untagged(text); + blocks.retain_mut(|block| { + let first = block.contents.remove(0); + let Some(id) = first.strip_prefix(&tag) else { return false; }; + + if block.is_doc { + panic!("Use plain (non-doc) comments with tags like {tag}:\n {first}"); + } - block.id = id.trim().to_string(); - block - }) - }) - .collect() + block.id = id.trim().to_string(); + true + }); + blocks } pub fn extract_untagged(text: &str) -> Vec<CommentBlock> { |
