diff options
author | Aleksey Kladov <[email protected]> | 2020-08-12 14:04:06 +0100 |
---|---|---|
committer | Aleksey Kladov <[email protected]> | 2020-08-12 14:04:06 +0100 |
commit | 1c359ab634edb81b51e3c7eadfb83d46c926e890 (patch) | |
tree | e098f492ffc5c2408642fb112a37dc31962fdd79 /crates/ra_assists/src/handlers/generate_new.rs | |
parent | 42a16926293ff5cb4da7d7dddebc2f4aea445c94 (diff) |
Replace SepBy with Itertools
Diffstat (limited to 'crates/ra_assists/src/handlers/generate_new.rs')
-rw-r--r-- | crates/ra_assists/src/handlers/generate_new.rs | 9 |
1 files changed, 5 insertions, 4 deletions
diff --git a/crates/ra_assists/src/handlers/generate_new.rs b/crates/ra_assists/src/handlers/generate_new.rs index b84aa24b6..32dfed274 100644 --- a/crates/ra_assists/src/handlers/generate_new.rs +++ b/crates/ra_assists/src/handlers/generate_new.rs | |||
@@ -1,9 +1,10 @@ | |||
1 | use hir::Adt; | 1 | use hir::Adt; |
2 | use itertools::Itertools; | ||
2 | use ra_syntax::{ | 3 | use ra_syntax::{ |
3 | ast::{self, AstNode, GenericParamsOwner, NameOwner, StructKind, VisibilityOwner}, | 4 | ast::{self, AstNode, GenericParamsOwner, NameOwner, StructKind, VisibilityOwner}, |
4 | T, | 5 | T, |
5 | }; | 6 | }; |
6 | use stdx::{format_to, SepBy}; | 7 | use stdx::format_to; |
7 | 8 | ||
8 | use crate::{AssistContext, AssistId, AssistKind, Assists}; | 9 | use crate::{AssistContext, AssistId, AssistKind, Assists}; |
9 | 10 | ||
@@ -52,8 +53,8 @@ pub(crate) fn generate_new(acc: &mut Assists, ctx: &AssistContext) -> Option<()> | |||
52 | let params = field_list | 53 | let params = field_list |
53 | .fields() | 54 | .fields() |
54 | .filter_map(|f| Some(format!("{}: {}", f.name()?.syntax(), f.ty()?.syntax()))) | 55 | .filter_map(|f| Some(format!("{}: {}", f.name()?.syntax(), f.ty()?.syntax()))) |
55 | .sep_by(", "); | 56 | .format(", "); |
56 | let fields = field_list.fields().filter_map(|f| f.name()).sep_by(", "); | 57 | let fields = field_list.fields().filter_map(|f| f.name()).format(", "); |
57 | 58 | ||
58 | format_to!(buf, " {}fn new({}) -> Self {{ Self {{ {} }} }}", vis, params, fields); | 59 | format_to!(buf, " {}fn new({}) -> Self {{ Self {{ {} }} }}", vis, params, fields); |
59 | 60 | ||
@@ -102,7 +103,7 @@ fn generate_impl_text(strukt: &ast::Struct, code: &str) -> String { | |||
102 | .map(|it| it.text().clone()); | 103 | .map(|it| it.text().clone()); |
103 | let type_params = | 104 | let type_params = |
104 | type_params.type_params().filter_map(|it| it.name()).map(|it| it.text().clone()); | 105 | type_params.type_params().filter_map(|it| it.name()).map(|it| it.text().clone()); |
105 | format_to!(buf, "<{}>", lifetime_params.chain(type_params).sep_by(", ")) | 106 | format_to!(buf, "<{}>", lifetime_params.chain(type_params).format(", ")) |
106 | } | 107 | } |
107 | 108 | ||
108 | format_to!(buf, " {{\n{}\n}}\n", code); | 109 | format_to!(buf, " {{\n{}\n}}\n", code); |