diff options
author | Domantas Jadenkus <[email protected]> | 2021-02-13 20:26:58 +0000 |
---|---|---|
committer | Domantas Jadenkus <[email protected]> | 2021-02-13 20:27:57 +0000 |
commit | ff7ea7c30843e576be6ab3fb70f79d8053006652 (patch) | |
tree | 0e284b6b5a860f35e211d43ca3315959ac99fe7b /crates/assists/src/utils.rs | |
parent | 3fdc556632e39145678219ace8476e12d7d70d41 (diff) |
use generate_impl_text in generate_from_impl
Diffstat (limited to 'crates/assists/src/utils.rs')
-rw-r--r-- | crates/assists/src/utils.rs | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/crates/assists/src/utils.rs b/crates/assists/src/utils.rs index 5dd32aef1..69c107f63 100644 --- a/crates/assists/src/utils.rs +++ b/crates/assists/src/utils.rs | |||
@@ -367,6 +367,16 @@ pub(crate) fn find_impl_block_end(impl_def: ast::Impl, buf: &mut String) -> Opti | |||
367 | // Generates the surrounding `impl Type { <code> }` including type and lifetime | 367 | // Generates the surrounding `impl Type { <code> }` including type and lifetime |
368 | // parameters | 368 | // parameters |
369 | pub(crate) fn generate_impl_text(adt: &ast::Adt, code: &str) -> String { | 369 | pub(crate) fn generate_impl_text(adt: &ast::Adt, code: &str) -> String { |
370 | generate_impl_text_inner(adt, None, code) | ||
371 | } | ||
372 | |||
373 | // Generates the surrounding `impl <trait> for Type { <code> }` including type | ||
374 | // and lifetime parameters | ||
375 | pub(crate) fn generate_trait_impl_text(adt: &ast::Adt, trait_text: &str, code: &str) -> String { | ||
376 | generate_impl_text_inner(adt, Some(trait_text), code) | ||
377 | } | ||
378 | |||
379 | fn generate_impl_text_inner(adt: &ast::Adt, trait_text: Option<&str>, code: &str) -> String { | ||
370 | let type_params = adt.generic_param_list(); | 380 | let type_params = adt.generic_param_list(); |
371 | let mut buf = String::with_capacity(code.len()); | 381 | let mut buf = String::with_capacity(code.len()); |
372 | buf.push_str("\n\nimpl"); | 382 | buf.push_str("\n\nimpl"); |
@@ -374,6 +384,10 @@ pub(crate) fn generate_impl_text(adt: &ast::Adt, code: &str) -> String { | |||
374 | format_to!(buf, "{}", type_params.syntax()); | 384 | format_to!(buf, "{}", type_params.syntax()); |
375 | } | 385 | } |
376 | buf.push(' '); | 386 | buf.push(' '); |
387 | if let Some(trait_text) = trait_text { | ||
388 | buf.push_str(trait_text); | ||
389 | buf.push_str(" for "); | ||
390 | } | ||
377 | buf.push_str(adt.name().unwrap().text()); | 391 | buf.push_str(adt.name().unwrap().text()); |
378 | if let Some(type_params) = type_params { | 392 | if let Some(type_params) = type_params { |
379 | let lifetime_params = type_params | 393 | let lifetime_params = type_params |