JetBrains RustRover Profile picture
The new Rust IDE by @JetBrains

Nov 1, 2022, 7 tweets

It’s hard to overstate the importance of refactoring your code. When done right, refactoring can reduce complexity and make your code more readable and easier to maintain.

In this thread 🧵 we'll show you some nifty refactorings in IntelliJ Rust.

👉 plugins.jetbrains.com/plugin/8182-ru…

The most important shortcut for working with refactorings in JetBrains IDEs is ⌃T, or Ctrl+Alt+Shift+T for Windows/Linux. It brings up the ‘Refactor this’ menu where you can simply choose the refactoring you need from the list.

plugins.jetbrains.com/plugin/8182-ru… #rustlang

One of the most frequently used refactorings is ‘Rename’. It renames any symbol and automatically corrects all its references in your code. Just place the caret on a symbol and press ⇧F6 / Shift+F6 to begin renaming.

plugins.jetbrains.com/plugin/8182-ru… #rustlang

The ‘Move’ refactoring (F6) can help you move top-level items within your project. Like with all other refactoring methods, the IDE will correct all the references automatically to ensure the modifications do not break your code.

plugins.jetbrains.com/plugin/8182-ru… #rustlang

If you need to move a single file, just drag and drop it and the ‘Move’ refactoring will do the rest! This process also supports re-exports.

plugins.jetbrains.com/plugin/8182-ru… #rustlang

‘Introduce Variable’ puts the result of an expression into a variable. Select the expression and press ⌥⌘V / Ctrl+Alt+V to replace it with the new variable.

‘Inline’ (⌥⌘N / Ctrl+Alt+N) does the opposite.

plugins.jetbrains.com/plugin/8182-ru… #rustlang

With the ‘Extract Method’ refactoring (⌥⌘M / Ctrl+Alt+M), you can take a code fragment, move it into a separate method, and replace the old code with a call to the method.

‘Inline’ (⌥⌘N / Ctrl+Alt+N) does the opposite.

plugins.jetbrains.com/plugin/8182-ru… #rustlang

Share this Scrolly Tale with your friends.

A Scrolly Tale is a new way to read Twitter threads with a more visually immersive experience.
Discover more beautiful Scrolly Tales like this.

Keep scrolling