我们今天来配置下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. String 类源码分析

    String 源码分析 String 类代表字符序列,Java 中所有的字符串字面量都作为此类的实例. String 对象是不可变的,它们的值在创建之后就不能改变,因此 String 是线程安全的. ...

  2. 浏览器端-W3School-JavaScript:Location 对象

    ylbtech-浏览器端-W3School-JavaScript:Location 对象 1.返回顶部 1. Location 对象 Location 对象 Location 对象包含有关当前 URL ...

  3. pip Fatal error in launcher: Unable to create process using '""'

    如果你装了python2.7, python3.5, 在两个版本的兼容问题上折腾很久了,  通过修改环境变量, 能够出现下面的界面, 恭喜你, 暂时解决了一些问题, 哈哈

  4. django 数据库操作详解

    Django配置使用mysql数据库 修改 settings.py 中的 DATABASES  注意:django框架不会自动帮我们生成mysql数据库,所以我们需要自己去创建. DATABASES ...

  5. os, sys, stat 模块使用

    1.设置文件权限: 注意:设置权限之前要导入下面三个模块,否则报错, import os, sys, stat os.chmod("/home/a.txt", stat.S_IXG ...

  6. python学习之内置函数(一)

    4.7 内置函数 4.7.1 内置函数(1) eval 执行字符串类型的代码,并返回最终结果. eval('2 + 2') # 4 n=81 eval("n + 4") # 85 ...

  7. HtML5与CSS3基础

    HTML标签 1.<a></a> 超链接标签 属性 href:跳转页面的连接 name:实现定锚功能,跳转同一页面不同位置(例返回顶部) target: (self, pare ...

  8. TCP中三次挥手四次握手

    1.TCP连接 手机能够使用联网功能是因为手机底层实现了TCP/IP协议,可以使手机终端通过无线网络建立TCP连接.TCP协议可以对上层网络提供接口,使上层网络数据的传输建立在“无差别”的网络之上. ...

  9. netcore 实现一个简单的Grpc 服务端和客户端

    参考资料,和详细背景不做赘述. 首先定义prop 文件 syntax ="proto3"; package RouteGrpc; service HelloWorld{ rpc S ...

  10. seata项目结构

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