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.
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.
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.
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.
‘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.
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.