From 59fa3a46c40d48f9de6f36f95568650e6c57c351 Mon Sep 17 00:00:00 2001 From: jackymao Date: Mon, 15 Aug 2022 18:38:25 +0800 Subject: [PATCH] add rust_data_type --- .../rust_toolchain.json" | 2 +- .../rustup_usage.json" | 2 +- .../cargo_usage.json" | 2 +- .../config.json" | 4 +- .../rust_data_type.json" | 7 ++ .../rust_data_type.md" | 82 +++++++++++++++++++ 6 files changed, 95 insertions(+), 4 deletions(-) create mode 100644 "data/1.rust\345\210\235\351\230\266/2.rust\345\237\272\346\234\254\346\246\202\345\277\265/1.Rust\346\225\260\346\215\256\347\261\273\345\236\213/rust_data_type.json" create mode 100644 "data/1.rust\345\210\235\351\230\266/2.rust\345\237\272\346\234\254\346\246\202\345\277\265/1.Rust\346\225\260\346\215\256\347\261\273\345\236\213/rust_data_type.md" diff --git "a/data/1.rust\345\210\235\351\230\266/1.\351\242\204\345\244\207\347\237\245\350\257\206/3.\350\256\244\350\257\206rust\345\267\245\345\205\267\351\223\276/rust_toolchain.json" "b/data/1.rust\345\210\235\351\230\266/1.\351\242\204\345\244\207\347\237\245\350\257\206/3.\350\256\244\350\257\206rust\345\267\245\345\205\267\351\223\276/rust_toolchain.json" index 3b59d0f..7635858 100644 --- "a/data/1.rust\345\210\235\351\230\266/1.\351\242\204\345\244\207\347\237\245\350\257\206/3.\350\256\244\350\257\206rust\345\267\245\345\205\267\351\223\276/rust_toolchain.json" +++ "b/data/1.rust\345\210\235\351\230\266/1.\351\242\204\345\244\207\347\237\245\350\257\206/3.\350\256\244\350\257\206rust\345\267\245\345\205\267\351\223\276/rust_toolchain.json" @@ -3,5 +3,5 @@ "author": "jacky_rust", "source": "rust_toolchain.md", "notebook_enable": false, - "exercise_id": "10ea7a4735644f6d8ede35025224887a" + "exercise_id": "" } \ No newline at end of file diff --git "a/data/1.rust\345\210\235\351\230\266/1.\351\242\204\345\244\207\347\237\245\350\257\206/4.rustup\347\232\204\344\275\277\347\224\250/rustup_usage.json" "b/data/1.rust\345\210\235\351\230\266/1.\351\242\204\345\244\207\347\237\245\350\257\206/4.rustup\347\232\204\344\275\277\347\224\250/rustup_usage.json" index 2c35752..99788fc 100644 --- "a/data/1.rust\345\210\235\351\230\266/1.\351\242\204\345\244\207\347\237\245\350\257\206/4.rustup\347\232\204\344\275\277\347\224\250/rustup_usage.json" +++ "b/data/1.rust\345\210\235\351\230\266/1.\351\242\204\345\244\207\347\237\245\350\257\206/4.rustup\347\232\204\344\275\277\347\224\250/rustup_usage.json" @@ -3,5 +3,5 @@ "author": "jacky_rust", "source": "rustup_usage.md", "notebook_enable": false, - "exercise_id": "10ea7a4735644f6d8ede35025224887a" + "exercise_id": "" } \ No newline at end of file diff --git "a/data/1.rust\345\210\235\351\230\266/1.\351\242\204\345\244\207\347\237\245\350\257\206/5.Cargo\347\232\204\344\275\277\347\224\250/cargo_usage.json" "b/data/1.rust\345\210\235\351\230\266/1.\351\242\204\345\244\207\347\237\245\350\257\206/5.Cargo\347\232\204\344\275\277\347\224\250/cargo_usage.json" index a83a00b..31d8c99 100644 --- "a/data/1.rust\345\210\235\351\230\266/1.\351\242\204\345\244\207\347\237\245\350\257\206/5.Cargo\347\232\204\344\275\277\347\224\250/cargo_usage.json" +++ "b/data/1.rust\345\210\235\351\230\266/1.\351\242\204\345\244\207\347\237\245\350\257\206/5.Cargo\347\232\204\344\275\277\347\224\250/cargo_usage.json" @@ -3,5 +3,5 @@ "author": "jacky_rust", "source": "cargo_usage.md", "notebook_enable": false, - "exercise_id": "10ea7a4735644f6d8ede35025224887a" + "exercise_id": "" } \ No newline at end of file diff --git "a/data/1.rust\345\210\235\351\230\266/2.rust\345\237\272\346\234\254\346\246\202\345\277\265/1.Rust\346\225\260\346\215\256\347\261\273\345\236\213/config.json" "b/data/1.rust\345\210\235\351\230\266/2.rust\345\237\272\346\234\254\346\246\202\345\277\265/1.Rust\346\225\260\346\215\256\347\261\273\345\236\213/config.json" index 74933d6..08a7c55 100644 --- "a/data/1.rust\345\210\235\351\230\266/2.rust\345\237\272\346\234\254\346\246\202\345\277\265/1.Rust\346\225\260\346\215\256\347\261\273\345\236\213/config.json" +++ "b/data/1.rust\345\210\235\351\230\266/2.rust\345\237\272\346\234\254\346\246\202\345\277\265/1.Rust\346\225\260\346\215\256\347\261\273\345\236\213/config.json" @@ -2,7 +2,9 @@ "node_id": "rust-0ab5f30784094edb91b971cf5d0b89b1", "keywords": [], "children": [], - "export": [], + "export": [ + "rust_data_type.json" + ], "keywords_must": [], "keywords_forbid": [] } \ No newline at end of file diff --git "a/data/1.rust\345\210\235\351\230\266/2.rust\345\237\272\346\234\254\346\246\202\345\277\265/1.Rust\346\225\260\346\215\256\347\261\273\345\236\213/rust_data_type.json" "b/data/1.rust\345\210\235\351\230\266/2.rust\345\237\272\346\234\254\346\246\202\345\277\265/1.Rust\346\225\260\346\215\256\347\261\273\345\236\213/rust_data_type.json" new file mode 100644 index 0000000..d283991 --- /dev/null +++ "b/data/1.rust\345\210\235\351\230\266/2.rust\345\237\272\346\234\254\346\246\202\345\277\265/1.Rust\346\225\260\346\215\256\347\261\273\345\236\213/rust_data_type.json" @@ -0,0 +1,7 @@ +{ + "type": "code_options", + "author": "jacky_rust", + "source": "rust_data_type.md", + "notebook_enable": false, + "exercise_id": "" + } \ No newline at end of file diff --git "a/data/1.rust\345\210\235\351\230\266/2.rust\345\237\272\346\234\254\346\246\202\345\277\265/1.Rust\346\225\260\346\215\256\347\261\273\345\236\213/rust_data_type.md" "b/data/1.rust\345\210\235\351\230\266/2.rust\345\237\272\346\234\254\346\246\202\345\277\265/1.Rust\346\225\260\346\215\256\347\261\273\345\236\213/rust_data_type.md" new file mode 100644 index 0000000..70a5dba --- /dev/null +++ "b/data/1.rust\345\210\235\351\230\266/2.rust\345\237\272\346\234\254\346\246\202\345\277\265/1.Rust\346\225\260\346\215\256\347\261\273\345\236\213/rust_data_type.md" @@ -0,0 +1,82 @@ +# rust 数据类型 + +使用计算机编程是为了处理各种各样的数据,每种数据都必定有类型。 + +这也就是说,类型是指数据在内存中是怎么存储,读取之后怎么解析这一段内存中的数据,以及对这种类型的数据可以怎么样进行操作。 + +Rust 语言设计者对于在内存中操作数据的要求非常高,比如在官方首页的 "Why Rust" 一节,提到了要做到 "memory-efficient" 和 "memory-safe",就是内存高效和内存安全,基于这样的设计目标,Rust 的数据类型设计非常精细。所以深入理解 Rust 类型是学好 Rust 编程的基础。 + + +下面简要说明一下具体类型。 + +Rust 的标量类型(scalar type) 是指表示为单一值的类型,有: +- 整数 int / integer +- 浮点数 float +- 布尔值 bool / Boolean +- 单个字符 char / character + +多个数据紧挨着排列的数据: +- 元组 Tuple +- 数组 Array +- 矢量 Vector +- 切片 Slice + +用户定义类型 +- 结构体 Struct +- 枚举 Enum +- 联合体 Union (较少用) + +其它类型 +- 函数 +- 闭包 +- 引用 +- 裸指针 +- 函数指针 +- Trait 对象 + +下面的代码不能打印出标量值的是: + +## 答案 + +```rust +fn main() { + println!("{}", (1,)); +} +``` + +## 选项 + +### 整数 + +```rust +fn main() { + println!("{}", 1); +} +``` + + +### 浮点数 + +```rust +fn main() { + println!("{}", -0.1); +} +``` + + +### 字符 + +```rust +fn main() { + println!("{}", ("1")); +} +``` + + + +