Skip to content

Commit de36433

Browse files
authored
Merge pull request #165 from michaelvanstraten/allow-passing-an-iterable-to-splice-children
Allow passing an iterable to `splice_children`
2 parents c4cb18a + dc1eb13 commit de36433

File tree

3 files changed

+12
-4
lines changed

3 files changed

+12
-4
lines changed

Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "rowan"
3-
version = "0.15.16"
3+
version = "0.16.0"
44
authors = ["Aleksey Kladov <[email protected]>"]
55
repository = "https://github.com/rust-analyzer/rowan"
66
license = "MIT OR Apache-2.0"

src/api.rs

+6-2
Original file line numberDiff line numberDiff line change
@@ -293,8 +293,12 @@ impl<L: Language> SyntaxNode<L> {
293293
self.raw.detach()
294294
}
295295

296-
pub fn splice_children(&self, to_delete: Range<usize>, to_insert: Vec<SyntaxElement<L>>) {
297-
let to_insert = to_insert.into_iter().map(cursor::SyntaxElement::from).collect::<Vec<_>>();
296+
pub fn splice_children<I: IntoIterator<Item = SyntaxElement<L>>>(
297+
&self,
298+
to_delete: Range<usize>,
299+
to_insert: I,
300+
) {
301+
let to_insert = to_insert.into_iter().map(cursor::SyntaxElement::from);
298302
self.raw.splice_children(to_delete, to_insert)
299303
}
300304
}

src/cursor.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -942,7 +942,11 @@ impl SyntaxNode {
942942
})
943943
}
944944

945-
pub fn splice_children(&self, to_delete: Range<usize>, to_insert: Vec<SyntaxElement>) {
945+
pub fn splice_children<I: IntoIterator<Item = SyntaxElement>>(
946+
&self,
947+
to_delete: Range<usize>,
948+
to_insert: I,
949+
) {
946950
assert!(self.data().mutable, "immutable tree: {}", self);
947951
for (i, child) in self.children_with_tokens().enumerate() {
948952
if to_delete.contains(&i) {

0 commit comments

Comments
 (0)