跳到主要内容

1.1-语言基础

Rust

Rust 最初是 Mozilla 公司的一个研宄性项目。 Firefox 是 Rust 产品应用的一个重要的例子。

安装

使用 powershell 安装

# 需要管理员权限
winget install --id Rustlang.Rustup

验证安装

rustc —verslon
一结果格式:
rustc x.y.z (abcabcabc yyyy-mm-dd)
一会显示最新稳定版的:版本号、commit hash、commit 日期

编译

先写一个示例

// rust.rs
fn main(){
println!("how are you")
}

其中

  • main 作为函数的入口
  • println! 表示一个宏,函数则没有叹号
  • 运行前必须先编译

rustc main.rs,会生成一个二进制文件(windows 会额外生成一个 .pdb 文件)

Cargo

rust 的构建工具和包管理工具,默认安装,可以构建代码,下载依赖,构建

cargo 配置文件格式为 TOML(Tom's Obvious, Minimal Language)以 .toml 结尾

检测安装 cargo -V

创建项目

cargo new hello_cargo

[package]
name = "platform-win"
version = "0.0.0"
description = "A Tauri App"
authors = ["you"]
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[build-dependencies]
tauri-build = { version = "1", features = [] }

[dependencies]
tauri = { version = "1", features = ["shell-open"] }
serde = { version = "1", features = ["derive"] }
serde_json = "1"

[features]
# This feature is used for production builds or when a dev server is not specified, DO NOT REMOVE!!
custom-protocol = ["tauri/custom-protocol"]

编译项目 cargo build

更新项目依赖 cargo udpate

参考文章

作者文章名称
软件工艺师https://www.bilibili.com/video/BV1hp4y1k7SV