我们今天来配置下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. apache配置静态缓存

    配置静态缓存:节省带宽,加快访问速度,提高用户体验.<IfModule mod_expires.c> ExpiresActive on ExpiresByType image/gif &q ...

  2. Python文件重命名代码

    import os def re_name(path): for file in os.listdir(path): file_path = os.path.join(path, file) # 判断 ...

  3. 【HANA系列】SAP ECLIPSE中创建ABAP项目的步骤

    公众号:SAP Technical 本文作者:matinal 原文出处:http://www.cnblogs.com/SAPmatinal/ 原文链接:[HANA系列]SAP ECLIPSE中创建AB ...

  4. vue,基于element的tree组件封装

    封装组件代码 // 组件:树 /* 参数说明-属性: 1.treeData:展示数据(array) 2.treeEmptyText:内容为空的时候展示的文本(String) 3.treeNodeKey ...

  5. python 包的概念

    包的概念 包的概念: 在python中包即使模块,是一系列功能的集合体, 为什么要用包? 提高开发效率 如何用包 import ... from ... import ..... 如何认识它就是一包 ...

  6. 第七周作业&实验报告5

     实验四 类的继承 实验目的 理解抽象类与接口的使用: 了解包的作用,掌握包的设计方法. 实验要求 掌握使用抽象类的方法. 掌握使用系统接口的技术和创建自定义接口的方法. 了解 Java 系统包的结 ...

  7. JavaScript中:地址引用的特性,导致静态初始值被修改

    问题分类 JavaScript,值引用,地址引用 问题描述 开发过程中,服务端将静态配置数据从mysql数据库中读取到内存中,方便调用. 在实现流派功能时,需从数据库中读取流派种类数据到内存中,由于其 ...

  8. [转帖]虚拟内存探究 -- 第二篇:Python 字节

    虚拟内存探究 -- 第二篇:Python 字节 http://blog.coderhuo.tech/2017/10/15/Virtual_Memory_python_bytes/ 是真看不懂哦     ...

  9. 刷机,twrp,安装xposed

    首先明白几个名词: recovery模式,类似于pc端的PE系统,每个手机都有自带的rec,但不好用,最好自己刷一个,现在市面最好用的是twrp fastboot模式,比recovery更底层,进入f ...

  10. Python和mysql的连接

    python与mysql的连接: 说明:前提是已近安装了mysql以及可视化工具(本人装的是Navicat) 1.在cmd下下载Python的第三方数据库包:pip install pymysql: ...