Skip to content

Commit 4362297

Browse files
committed
Add edit utility for adding an associated item list to a impl def
1 parent 82dc4af commit 4362297

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

crates/syntax/src/ast/edit.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,22 @@ where
9393
}
9494
}
9595

96+
impl ast::Impl {
97+
#[must_use]
98+
pub fn with_items(&self, items: ast::AssocItemList) -> ast::Impl {
99+
let mut to_insert: ArrayVec<[SyntaxElement; 2]> = ArrayVec::new();
100+
if let Some(old_items) = self.assoc_item_list() {
101+
let to_replace: SyntaxElement = old_items.syntax().clone().into();
102+
to_insert.push(items.syntax().clone().into());
103+
self.replace_children(single_node(to_replace), to_insert)
104+
} else {
105+
to_insert.push(make::tokens::single_space().into());
106+
to_insert.push(items.syntax().clone().into());
107+
self.insert_children(InsertPosition::Last, to_insert)
108+
}
109+
}
110+
}
111+
96112
impl ast::AssocItemList {
97113
#[must_use]
98114
pub fn append_items(

0 commit comments

Comments
 (0)