]> git.lizzy.rs Git - rust.git/commitdiff
refactor: use Itertools::intersperse
authorCôme ALLART <come.allart@etu.emse.fr>
Sat, 11 Dec 2021 19:41:23 +0000 (20:41 +0100)
committerCôme ALLART <come.allart@etu.emse.fr>
Sat, 11 Dec 2021 19:41:23 +0000 (20:41 +0100)
crates/ide_assists/src/handlers/generate_documentation_template.rs

index 5205a8ac7edb753edbbb7b0c9dac424eef6f31f8..a2fe3463b6faf5042f44a46358fe5819f87d2780 100644 (file)
@@ -1,5 +1,6 @@
 use hir::{AsAssocItem, HasVisibility, ModuleDef, Visibility};
 use ide_db::assists::{AssistId, AssistKind};
+use itertools::Itertools;
 use stdx::to_lower_snake_case;
 use syntax::{
     ast::{self, edit::IndentLevel, HasDocComments, HasName},
@@ -354,7 +355,7 @@ fn arguments_from_params(param_list: &ast::ParamList) -> String {
         },
         _ => "_".to_string(),
     });
-    intersperse_string(args_iter, ", ")
+    Itertools::intersperse(args_iter, ", ".to_string()).collect()
 }
 
 /// Helper function to build a function call. `None` if expected `self_name` was not provided
@@ -430,19 +431,6 @@ fn returns_a_value(ast_func: &ast::Fn) -> bool {
     }
 }
 
-/// Helper function to concatenate string with a separator between them
-fn intersperse_string(mut iter: impl Iterator<Item = String>, separator: &str) -> String {
-    let mut result = String::new();
-    if let Some(first) = iter.next() {
-        result.push_str(&first);
-    }
-    for string in iter {
-        result.push_str(separator);
-        result.push_str(&string);
-    }
-    result
-}
-
 #[cfg(test)]
 mod tests {
     use crate::tests::{check_assist, check_assist_not_applicable};