Add pub(crate) to functions generated in other module

This commit is contained in:
Timo Freiberg 2020-04-20 18:36:12 +02:00
parent 74780a15f6
commit f2f882bc44
2 changed files with 27 additions and 46 deletions

View file

@ -303,6 +303,10 @@ pub fn add_trailing_newlines(amount_of_newlines: usize, t: impl AstNode) -> ast:
ast_from_text(&format!("{}{}", t.syntax(), newlines))
}
pub fn add_pub_crate_modifier(fn_def: ast::FnDef) -> ast::FnDef {
ast_from_text(&format!("pub(crate) {}", fn_def))
}
fn ast_from_text<N: AstNode>(text: &str) -> N {
let parse = SourceFile::parse(text);
let node = parse.tree().syntax().descendants().find_map(N::cast).unwrap();