From cbc6f94573d7f4601b739e001de5d5f71ec9b552 Mon Sep 17 00:00:00 2001 From: Wesley Norris Date: Sat, 9 Nov 2019 10:56:36 -0500 Subject: Add add_new assist Adds a new assist to autogenerate a new fn based on the selected struct, excluding tuple structs and unions. The fn will inherit the same visibility as the struct and the assist will attempt to reuse any existing impl blocks that exist at the same level of struct. --- docs/user/assists.md | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'docs/user') diff --git a/docs/user/assists.md b/docs/user/assists.md index 303353e74..8da7578e2 100644 --- a/docs/user/assists.md +++ b/docs/user/assists.md @@ -150,6 +150,27 @@ use std::collections::HashMap; fn process(map: HashMap) {} ``` +## `add_new` + +Adds a new inherent impl for a type. + +```rust +// BEFORE +struct Ctx { + data: T,┃ +} + +// AFTER +struct Ctx { + data: T, +} + +impl Ctx { + fn new(data: T) -> Self { Self { data } } +} + +``` + ## `apply_demorgan` Apply [De Morgan's law](https://en.wikipedia.org/wiki/De_Morgan%27s_laws). -- cgit v1.2.3