How to create and run Rust code with a single Sublime Text shortcut?

I installed the Rust Enhanced plugin on Sublime Text 3126, and I can create and run a program *.rsopen in Sublime Text.

In fact, a process is a nightmare:

  • Click Cmd+Shift+B
  • Choose Rustto compile
  • Make sure there are no errors.
  • Click Cmd+Shift+B
  • Select Rust - Runto run the last executable file.

Cmd+B just repeats the last command executed.

How can this be shortened in one shortcut?

+4
source share
3 answers

A simple custom assembly that I use to create and run from a single shortcut:

{
    "shell_cmd": "rustc $file",
    "selector": "source.rust",

    "variants": 
    [
        {
            "name": "Build & Run",
            "selector": "source.rust",
            "shell_cmd": "rustc $file && ./$file_base_name",
            "windows":
            {
                "shell_cmd": "rustc $file && $file_base_name.exe"
            }
        }
    ]
}
+2
source

" " Sublime.

(byzon.sublime-build, cf) c:\Users\$username\AppData\Roaming\Sublime Text 3\Packages\User\ :

{ "cmd": ["c:/spool/bin/sublime_build.exe", "--build=$file"],
  // New Rust
  "file_regex": "--> (?:[\\w\\\\/\\.]+[\\\\/])?([\\w\\.]+\\.rs):(\\d+):(\\d+)",
  // Old Rust
  //"file_regex": "^(?:[\\w\\./]+/)?([\\w\\.]+\\.rs):(\\d+):(\\d+)",
  "selector": "source.rust, source.php" }

"build system" , "Tools/Build System" ( ), Ctrl + B script (, , Rust).

, - . , script, , , , Ctrl + BI , . Docker. , script .

+1

, Quora, , 1. :

  • .
  • From the command line (Shift + right click when inside a folder in Windows), call

    cargo new PROJECT_NAME --bin

  • This creates the main.rs file inside the src folder. Open it and skip the code.

  • Run Ctrl + Shift + Bonce and select Cargo - Run . From now on, you can build (and run) only with Ctrl + B.
+1
source

Source: https://habr.com/ru/post/1658453/


All Articles