]> git.lizzy.rs Git - rust.git/commitdiff
Add larger example for "Convert to named struct" assist
authorunexge <unexge@gmail.com>
Wed, 21 Apr 2021 07:57:36 +0000 (10:57 +0300)
committerunexge <unexge@gmail.com>
Wed, 21 Apr 2021 07:57:36 +0000 (10:57 +0300)
crates/ide_assists/src/handlers/convert_tuple_struct_to_named_struct.rs
crates/ide_assists/src/tests/generated.rs

index b68b1d06f7604d2d17c0726d819c9e31a3507dd3..ee6ddfbc6012d60a6cab2c3b85642123907e177d 100644 (file)
 // Converts tuple struct to struct with named fields.
 //
 // ```
-// struct Inner;
-// struct A$0(Inner);
+// struct Point$0(f32, f32);
+//
+// impl Point {
+//     pub fn new(x: f32, y: f32) -> Self {
+//         Point(x, y)
+//     }
+//
+//     pub fn x(&self) -> f32 {
+//         self.0
+//     }
+//
+//     pub fn y(&self) -> f32 {
+//         self.1
+//     }
+// }
 // ```
 // ->
 // ```
-// struct Inner;
-// struct A { field1: Inner }
+// struct Point { field1: f32, field2: f32 }
+//
+// impl Point {
+//     pub fn new(x: f32, y: f32) -> Self {
+//         Point { field1: x, field2: y }
+//     }
+//
+//     pub fn x(&self) -> f32 {
+//         self.field1
+//     }
+//
+//     pub fn y(&self) -> f32 {
+//         self.field2
+//     }
+// }
 // ```
 pub(crate) fn convert_tuple_struct_to_named_struct(
     acc: &mut Assists,
index 53f455adf9def6ef1846c6c9bdaadde0cd409a8c..f4a4749c80669d7a3dd270112d5ddc6b16063915 100644 (file)
@@ -296,12 +296,38 @@ fn doctest_convert_tuple_struct_to_named_struct() {
     check_doc_test(
         "convert_tuple_struct_to_named_struct",
         r#####"
-struct Inner;
-struct A$0(Inner);
+struct Point$0(f32, f32);
+
+impl Point {
+    pub fn new(x: f32, y: f32) -> Self {
+        Point(x, y)
+    }
+
+    pub fn x(&self) -> f32 {
+        self.0
+    }
+
+    pub fn y(&self) -> f32 {
+        self.1
+    }
+}
 "#####,
         r#####"
-struct Inner;
-struct A { field1: Inner }
+struct Point { field1: f32, field2: f32 }
+
+impl Point {
+    pub fn new(x: f32, y: f32) -> Self {
+        Point { field1: x, field2: y }
+    }
+
+    pub fn x(&self) -> f32 {
+        self.field1
+    }
+
+    pub fn y(&self) -> f32 {
+        self.field2
+    }
+}
 "#####,
     )
 }