Rust-learning-day2

今日主要围绕教程进行学习并记录有用的笔记

1. Prepare

前天已经将环境搭好,顺手找了一下在线的英文网和中文网:

前言 - Rust 程序设计语言 简体中文版

The Rust Programming Language - The Rust Programming Language

1.1 Introduction

High-level ergonomics(效率) and low-level control are often at odds in programming language design; Rust challenges that conflict.

Rust also brings contemporary developer tools to the systems programming world:

  • Cargo, the included dependency manager and build tool(内置的依赖管理器和构建工具), makes adding, compiling, and managing dependencies painless and consistent across the Rust ecosystem.
  • The Rustfmt formatting tool ensures a consistent coding style across developers.
  • The Rust Language Server powers Integrated Development Environment (IDE) integration for code completion and inline error messages.

1.2 Format

# install 
rustup component add rustfmt

# fmt
cargo fmt

# build
cargo build

# fix
cargo fix

1.3 Lint

# install
rustup component add clippy

# lint
cargo clippy

2. Getting started

2.1 Installing Rust

# 安装
curl --proto '=https' --tlsv1.2 https://sh.rustup.rs -sSf | sh

# 更新
rustup update

# 卸载
rustup self uninstall

# 文档
rustup doc

2.2 Hello, world!

2.3 Cargo, Rust’s package manager and build system

  • 扩展名为 .rs 的源文件在rustc编译后得到可执行文件(在 Windows 下是 main.exe,其它平台是 main),以及当使用 CMD 时会有一个包含调试信息、扩展名为 .pdb 的文件

Tips:

1. Rust 的缩进风格使用 4 个空格,而不是 1 个制表符(tab)

2. 如果文件名包含多个单词,那么按照命名习惯,应当使用下划线来分隔单词。例如命名为 hello_world.rs,而不是 helloworld.rs
3. 
大部分 Rust 代码行以分号结尾

4. Rust 中,代码包被称为 crates

2.4 Build & Release

cargo build --release

教程来源
Introduction - The Rust Programming Language

  • 19
    点赞
  • 26
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值