[Easy to understand series | rustlang language | zero-based | Getting Started | (2)]

Today, we configure the next vscode + rust.

vscode develop rust easily. But a little pit configuration, we believe vscode very simple, very perfect.

But a lot of students here are also many problems.

We are here simply recording configured in under win7, follow me step by step, should you can create your Dragon sword.

First, we install the plugin:

Rust Extension Pack
Rust Test Explorer
 
Then open the article in the project: hello-rustSee: https: //www.cnblogs.com/gyc567/p/11887935.html
Open command palette (Ctrl-Shift-P): Input: build, then choose: Tasks: Configure Default Build Task, select: Rust: cargo build

 

 

 vscode will automatically generate a json file:

 // See https://go.microsoft.com/fwlink/?LinkId=733558 
    // for the documentation about the tasks.json format
    "version": "2.0.0",
    "tasks": [
        {
            "label": "cargo run",
            "type": "shell",
            "command": "cargo",
            "args": [
                "run"
            ],
            "group": {
                "kind": "build",
                "isDefault": true
            }
        }
 
 
 Here, we just press "CTRL + SHIFT + P", select: "Task: Run Build Task", or direct shortcut keys "CTRL + F9"
 

 

 

VSCODE automatically BUILD, print and display the results in a terminal window:
-------------------------------------------------------
> Executing task: cargo run <

   Compiling hello-rust v0.1.0 (E:\code\rustProject\hello-rust)
    Finished dev [unoptimized + debuginfo] target(s) in 2.11s
     Running `target\debug\hello-rust.exe`
----------------------------
| Hello fellow Rustaceans! |
----------------------------
              \
               \
                  _~^~^~_
              \) /  o o  \ (/
                '_   -   _'
                / '-----' \

Terminal will be reused by tasks, press any key to close it.
 
--------------------------------------------------------------
 

 下面配置测试task:

先在main函数下面增加测试代码:

#[test]
fn should_fail() {
    unimplemented!();
}

保存后,按快捷键:“CTRL+SHIFT+P”,输入:Task,选择“Tasks: Configure Default Test Task”,然后选择:“Rust: cargo test”

 

 

 

 

 


vscode自动生成:
{
            "type": "cargo",
            "subcommand": "test",
            "problemMatcher": [
                "$rustc"
            ],
            "group": {
                "kind": "test",
                "isDefault": true
            }
        }

 

 

保存后,按按快捷键:“CTRL+SHIFT+P”,输入:Task:Run test Task,回车。
vscode自动运行测试用例,并打印结果:

---------------------------------------

> Executing task: cargo test <

   Compiling hello-rust v0.1.0 (E:\code\rustProject\hello-rust)
    Finished dev [unoptimized + debuginfo] target(s) in 1.77s
     Running target\debug\deps\hello_rust-bfa762df5afd173e.exe

running 1 test
test should_fail ... FAILED

failures:

---- should_fail stdout ----
thread 'should_fail' panicked at 'not yet implemented', src\main.rs:14:5
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace.


failures:
    should_fail

. Test Result: FAILED 0 passed; failed. 1; 0 ignored; Measured 0; 0 OUT Filtered

error: Test failed, to rerun, Pass 'Hello --bin-Rust'
of The Terminal terminated with Process Exit code:. 1

Terminal Will BE by the Reused Tasks, Press Key to the any use Close IT.
----------------------------------------- ------------------

If you successfully come this far, congratulations, you have basically configured rust development environment.
如果遇到什么问题,欢迎加入:rust新手群,在这里我可以提供一些简单的帮助,加微信:360369487,注明:博客园+rust



Guess you like

Origin www.cnblogs.com/gyc567/p/11888103.html