rust

文章目录

  • rust
    • Cargo
    • [Creating a rust project](#Creating a rust project)
  • [How to Debug Rust Programs using VSCode](#How to Debug Rust Programs using VSCode)
    • [basic debugging](#basic debugging)
    • [How to pass arguments in Rust debugging with VS Code.](#How to pass arguments in Rust debugging with VS Code.)
  • References

rust

Cargo

Cargo is a package management tool used for downloading, compiling, updating, and managing dependencies in Rust. It is installed automatically when Rust is installed and does not require any manual intervention from the user.

Creating a rust project

bash 复制代码
cargo new hello_world

Project Structure

bash 复制代码
$ cd hello_world
$ tree .
.
├── Cargo.toml
└── src
    └── main.rs

1 directory, 2 files

Cargo.toml is the configuration file used by Cargo.

复制代码
[package]
name = "hello_world"
version = "0.1.0"
edition = "2021"

[dependencies]

The above is the complete content of the Cargo.toml file, which is known as the manifest and contains all the metadata needed for Cargo to compile the program.

src/main.rs内容如下

复制代码
fn main() {
    println!("Hello, world!");
}

It can be seen that Cargo has also automatically generated a "Hello World" program or binary package for us, and has compiled and built the program.

bash 复制代码
$ cargo build
   Compiling hello_world v0.1.0 (file:///path/to/package/hello_world)

Then run the compiled binary executable file:

bash 复制代码
$ ./target/debug/hello_world
Hello, world!

Notice the "debug" in the path? It indicates that we just compiled in Debug mode, which is mainly used for testing purposes. If we want to perform production compilation, we need to use the Release mode with cargo build --release, and then run it with ./target/release/hello_world.

In addition to the compile + run method mentioned above, in daily development, we can also use a simple command to run it directly:

bash 复制代码
$ cargo run
     Fresh hello_world v0.1.0 (file:///path/to/package/hello_world)
   Running `target/hello_world`
Hello, world!

cargo run will automatically compile and run the program for us. Of course, this command also supports the Release mode: cargo run --release.

How to Debug Rust Programs using VSCode

basic debugging

After consulting the official documentation on debugging Rust with VS Code at https://code.visualstudio.com/docs/languages/rust#_debugging, ↗ it is found that the recommended debugging extensions are:

Microsoft C++ (ms-vscode.cpptools) - on Windows

CodeLLDB (vadimcn.vscode-lldb) - on macOS/Linux

"After installing the debugging extension, you can start debugging."

How to pass arguments in Rust debugging with VS Code.

When using CodeLLDB for debugging, consult the CodeLLDB debugging documentation at https://github.com/vadimcn/codelldb/blob/v1.9.2/MANUAL.md#starting-a-new-debug-session ↗ to learn that a launch.json configuration file needs to be created in the .vscode directory.

The configuration file should have the following contents::

复制代码
{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "Launch",
            "type": "lldb",
            "request": "launch",
            "program": "${workspaceFolder}/target/debug/yrh_test",
            "args": ["llama", "${workspaceFolder}/model/llama/open_llama_3b-f16.bin"],
        }
    ]
}

References

https://zhuanlan.zhihu.com/p/470251959

相关推荐
paopaokaka_luck1 小时前
基于SpringBoot+Vue的电影售票系统(协同过滤算法)
vue.js·spring boot·后端
专注VB编程开发20年1 小时前
javascript的类,ES6模块写法在VSCODE中智能提示
开发语言·javascript·vscode
IT_10247 小时前
Spring Boot项目开发实战销售管理系统——系统设计!
大数据·spring boot·后端
ai小鬼头8 小时前
AIStarter最新版怎么卸载AI项目?一键删除操作指南(附路径设置技巧)
前端·后端·github
Touper.8 小时前
SpringBoot -- 自动配置原理
java·spring boot·后端
黄雪超8 小时前
JVM——函数式语法糖:如何使用Function、Stream来编写函数式程序?
java·开发语言·jvm
ThetaarSofVenice8 小时前
对象的finalization机制Test
java·开发语言·jvm
思则变9 小时前
[Pytest] [Part 2]增加 log功能
开发语言·python·pytest
一只叫煤球的猫9 小时前
普通程序员,从开发到管理岗,为什么我越升职越痛苦?
前端·后端·全栈
一只鹿鹿鹿9 小时前
信息化项目验收,软件工程评审和检查表单
大数据·人工智能·后端·智慧城市·软件工程