我们今天来配置下vscode+rust。

vscode开发rust很方便。但配置有点坑,我们都认为vscode很简单,很完善。

但这里很多同学也出现不少问题。

我们在这里简单记录下win7下配置的过程,跟着我一步步来,应该就可打造你的屠龙宝刀。

首先,我们安装插件:

Rust Extension Pack
Rust Test Explorer
 
然后打开上一篇文章的工程:hello-rust,见:https://www.cnblogs.com/gyc567/p/11887935.html
打开command palette (Ctrl-Shift-P):输入:build,然后选择:Tasks: Configure Default Build Task,再选择:Rust: cargo build

vscode会自动生成一个json文件:

 // 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
            }
        }
 
 
 这里,我们直接按“CTRL+SHIFT+P”,选择:“Task:Run Build Task”,或者直接按快捷键“CTRL+F9”
 

VSCODE会自动BUILD,并在终端窗口显示打印结果:
-------------------------------------------------------
> 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; 1 failed; 0 ignored; 0 measured; 0 filtered out error: test failed, to rerun pass '--bin hello-rust'
The terminal process terminated with exit code: 1 Terminal will be reused by tasks, press any key to close it.
----------------------------------------------------------- 下面继续配置DEBUG环境。
这里参照这个文章:https://www.forrestthewoods.com/blog/how-to-debug-rust-with-visual-studio-code/
简单来说,你按如下几步来配置就可以:
1.安装:
C/C++ extension.
Native Debug extension
2.在debug面板,新建一个新的配置,如下:

然后选择:“C++ (Windows)” environment

会自动生成launch.json代码,如下 :

{
    // Use IntelliSense to learn about possible attributes.
    // Hover to view descriptions of existing attributes.
    // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
    "version": "0.2.0",
    "configurations": [
        
        {
            "name": "(Windows) Launch",
            "type": "cppvsdbg",
            "request": "launch",
            "program": "${workspaceFolder}/target/debug/hello-rust.exe",
            "args": [],
            "stopAtEntry": false,
            "cwd": "${workspaceFolder}",
            "environment": [],
            "externalConsole": false
        }
    ]
}

其中program的值改为你自己的exe的路径,比如我的就是:

${workspaceFolder}/target/debug/hello-rust.exe
这时,你直接按F5,你就进入debug状态,你现在可以设置断点了。
如果,你顺利走到这一步,恭喜你,你已经基本配置好rust的开发环境。
如果遇到什么问题,欢迎加入:rust新手群,在这里我可以提供一些简单的帮助,加微信:360369487,注明:博客园+rust

[易学易懂系列|rustlang语言|零基础|快速入门|(2)|VSCODE配置]的更多相关文章

  1. [易学易懂系列|rustlang语言|零基础|快速入门|(28)|实战5:实现BTC价格转换工具]

    [易学易懂系列|rustlang语言|零基础|快速入门|(28)|实战5:实现BTC价格转换工具] 项目实战 实战5:实现BTC价格转换工具 今天我们来开发一个简单的BTC实时价格转换工具. 我们首先 ...

  2. [易学易懂系列|rustlang语言|零基础|快速入门|(27)|实战4:从零实现BTC区块链]

    [易学易懂系列|rustlang语言|零基础|快速入门|(27)|实战4:从零实现BTC区块链] 项目实战 实战4:从零实现BTC区块链 我们今天来开发我们的BTC区块链系统. 简单来说,从数据结构的 ...

  3. [易学易懂系列|rustlang语言|零基础|快速入门|(26)|实战3:Http服务器(多线程版本)]

    [易学易懂系列|rustlang语言|零基础|快速入门|(26)|实战3:Http服务器(多线程版本)] 项目实战 实战3:Http服务器 我们今天来进一步开发我们的Http服务器,用多线程实现. 我 ...

  4. [易学易懂系列|rustlang语言|零基础|快速入门|(25)|实战2:命令行工具minigrep(2)]

    [易学易懂系列|rustlang语言|零基础|快速入门|(25)|实战2:命令行工具minigrep(2)] 项目实战 实战2:命令行工具minigrep 我们继续开发我们的minigrep. 我们现 ...

  5. [易学易懂系列|rustlang语言|零基础|快速入门|(24)|实战2:命令行工具minigrep(1)]

    [易学易懂系列|rustlang语言|零基础|快速入门|(24)|实战2:命令行工具minigrep(1)] 项目实战 实战2:命令行工具minigrep 有了昨天的基础,我们今天来开始另一个稍微有点 ...

  6. [易学易懂系列|rustlang语言|零基础|快速入门|(23)|实战1:猜数字游戏]

    [易学易懂系列|rustlang语言|零基础|快速入门|(23)|实战1:猜数字游戏] 项目实战 实战1:猜数字游戏 我们今天来来开始简单的项目实战. 第一个简单项目是猜数字游戏. 简单来说,系统给了 ...

  7. [易学易懂系列|rustlang语言|零基础|快速入门|(5)|生命周期Lifetime]

    [易学易懂系列|rustlang语言|零基础|快速入门|(5)] Lifetimes 我们继续谈谈生命周期(lifttime),我们还是拿代码来说话: fn main() { let mut a = ...

  8. [易学易懂系列|rustlang语言|零基础|快速入门|(22)|宏Macro]

    [易学易懂系列|rustlang语言|零基础|快速入门|(22)|宏Macro] 实用知识 宏Macro 我们今天来讲讲Rust中强大的宏Macro. Rust的宏macro是实现元编程的强大工具. ...

  9. [易学易懂系列|rustlang语言|零基础|快速入门|(21)|智能指针]

    [易学易懂系列|rustlang语言|零基础|快速入门|(21)|智能指针] 实用知识 智能指针 我们今天来讲讲Rust中的智能指针. 什么是指针? 在Rust,指针(普通指针),就是保存内存地址的值 ...

  10. [易学易懂系列|rustlang语言|零基础|快速入门|(20)|错误处理]

    [易学易懂系列|rustlang语言|零基础|快速入门|(20)|错误处理] 实用知识 错误处理 我们今天来讲讲Rust中的错误处理. 很多语言都有自己的错误处理方式,比如,java是异常处理机制. ...

随机推荐

  1. PermissionUtils

    import android.annotation.TargetApi; import android.app.Activity; import android.content.Context; im ...

  2. 细说Linux下的虚拟主机那些事儿

    细说Linux下的虚拟主机那些事儿 我们知道Linux操作系统是目前在服务器上应用广泛的操作系统.在Linux操作系统下的虚拟主机是不是就是我们常说的Linux虚拟主机呢?其实从专业方面说并不是,它是 ...

  3. cocos2dx[3.2](5) 屏幕适配

    1.两个分辨率 1.1.窗口分辨率 在AppDelegate.cpp中有个设置窗口分辨率的函数.该函数是设置了我们预想设备的屏幕大小,也就是应用程序窗口的大小. // glView->setFr ...

  4. stringbuffer.tostring引发的 Java heap space

    今天在测试“生成报告“功能时,出现了这个问题,java抛出java.lang.OutOfMemoryError: Java heap space: 由于开发使用的tomcat是统一配置的,而且其他地方 ...

  5. MySQL改密

    一.未进入之前: 1.grep password /var/log/mysqld.log   得出默认密码2.更改密码    mysqladmin -uroot -p'd-tlbwIgP3e2' pa ...

  6. htc 手机

    是否解锁locked unlocked 然后刷入REC

  7. mysql——前面内容——前期整理笔记00

    ), sname ), sage ), ssex ) ); ','zhaolei','1990-01-01','nan'); ','qiandian','1990-12-21','nan'); ',' ...

  8. 从零开始学习GDI+ (二) 基本概念与基本操作

    从零开始学习GDI+ (一)我的第一个GDI+程序 上文给新手学习GDI+讲述了vs环境等的准备工作,并且可以直接用GDI+绘图了.本文开始,讲述的可能偏理论,建议学习的过程中大胆尝试,多使用API. ...

  9. seata项目结构

    1. 概述 在拉取 Seata 项目后,我们会发现拆分了好多 Maven 项目.

  10. 洛谷 P1879 玉米田Corn Fields 题解

    题面 一道思维难度不大的状态压缩,也并不卡常,但细节处理要格外注意: f[i][j]表示前i行最后一行状态是j的方案数 #include <bits/stdc++.h> #define p ...