succinct code
use ide_db::defs::{Definition, NameRefClass};
+use itertools::Itertools;
use syntax::{ast, AstNode, SyntaxKind, T};
use crate::{
@@ -94,8 +95,7 @@ pub(crate) fn add_turbo_fish(acc: &mut Assists, ctx: &AssistContext) -> Option<(
builder.insert_snippet(cap, ident.text_range().end(), snip)
}
None => {
- let fish_head =
- std::iter::repeat("_").take(number_of_arguments).collect::<Vec<_>>().join(", ");
+ let fish_head = std::iter::repeat("_").take(number_of_arguments).format(", ");
let snip = format!("::<{}>", fish_head);
builder.insert(ident.text_range().end(), snip);
}
@@ -105,12 +105,9 @@ pub(crate) fn add_turbo_fish(acc: &mut Assists, ctx: &AssistContext) -> Option<(
/// This will create a snippet string with tabstops marked
fn get_snippet_fish_head(number_of_arguments: usize) -> String {
- let mut fish_head = String::new();
- let mut i = 1;
- while i < number_of_arguments {
- fish_head.push_str(&format!("${{{}:_}},", i));
- i = i + 1;
- }
+ let mut fish_head = (1..number_of_arguments)
+ .format_with("", |i, f| f(&format_args!("${{{}:_}}, ", i)))
+ .to_string();
// tabstop 0 is a special case and always the last one
fish_head.push_str("${0:_}");
