Add edit utility for adding an associated item list to a impl def

This commit is contained in:
Matt Hooper 2020-09-21 00:38:18 +01:00
parent 82dc4af5de
commit 4362297a0b

View file

@ -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 { impl ast::AssocItemList {
#[must_use] #[must_use]
pub fn append_items( pub fn append_items(