我们今天来配置下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. 转载-Mysql主主复制架构配置

    Mysql主主复制架构配置 转载:原始出处 http://luoweiro.blog.51cto.com/2186161/658550MySQL主主复制结构区别于主从复制结构.在主主复制结构中,两台服 ...

  2. 破解root

    启动grub按E,进入编辑,ro 改为 rw init=/sysroot/bin/sh然后Ctrl+X进入单用户# chroot /sysroot# passwd root# touch /.auto ...

  3. JDBC操作数据库的基本操作

    JDBC操作数据库的基本步骤: 1)加载(注册)数据库驱动(到JVM). 2)建立(获取)数据库连接. 3)创建(获取)数据库操作对象. 4)定义操作的SQL语句. 5)执行数据库操作. 6)获取并操 ...

  4. javascript中几种为false的值

    如果JavaScript预期某个位置应该是布尔值,会将该位置上现有的值自动转为布尔值.转换规则是除了下面六个值被转为false,其他值都视为true. undefined null  false  0 ...

  5. Redis 下载与配置window服务

    1.Redis下载 Git下载地址:https://github.com/MicrosoftArchive/redis/releases 2.配置Window服务 步骤一:在 Redis目录 输入 c ...

  6. P1706 【全排列问题】

    超级无敌大题面~~ 这题倒也花了我不少时间,不停想节省空间,但这也确实是最省的了... 主要思路呢,要注意标记数有没有选过,并标记每个数的输出顺序.. 具体注释见代码: #include<cst ...

  7. Markdown基础语法总结

    目录 区块元素 标题 列表 区块引用 代码区块 分隔线 段落和换行 区段元素 链接 强调 代码 图片 转义 标题 <a name="title"></a> ...

  8. python小游戏2

    import hashlib 过段时间会来解释下hashlib的源码(能力有限请大家谅解)#根据md5模块来加密密码 def pwd_md5(pwd): ''' 加密用户输入过来的密码 :param ...

  9. abp.event.on与abp.event.off使用

    apb的全局事件 var eventName = "app.createOrEditFieldModalSaved"; var reloadPage = function () { ...

  10. 使用rsync在linux(服务端)与windows(客户端)之间同步

    说明: 1.RsyncServer服务端 系统:CentOS 6.8 IP地址:192.168.247.141 2.Rsync客户端 系统:Windows10 实现目的: Rsync客户端同步服务端/ ...