Add edit utility for adding an associated item list to a impl def
@@ -93,6 +93,22 @@ where
}
}
+impl ast::Impl {
+ #[must_use]
+ pub fn with_items(&self, items: ast::AssocItemList) -> ast::Impl {
+ let mut to_insert: ArrayVec<[SyntaxElement; 2]> = ArrayVec::new();
+ if let Some(old_items) = self.assoc_item_list() {
+ let to_replace: SyntaxElement = old_items.syntax().clone().into();
+ to_insert.push(items.syntax().clone().into());
+ self.replace_children(single_node(to_replace), to_insert)
+ } else {
+ to_insert.push(make::tokens::single_space().into());
+ to_insert.push(items.syntax().clone().into());
+ self.insert_children(InsertPosition::Last, to_insert)
+ }
+ }
+}
+
impl ast::AssocItemList {
#[must_use]
pub fn append_items(
