随笔分类 -  Rust

上一页 1 ··· 8 9 10 11 12 13 下一页
摘要:环境 Rust 1.56.1 VSCode 1.61.2 概念 参考:https://doc.rust-lang.org/stable/rust-by-example/trait.html 先简单地认为 trait 就是其它语言中的接口,可以为不同的类型定义同一种行为。 示例 Person stru 阅读全文
posted @ 2021-11-30 22:55 jiangbo4444 阅读(289) 评论(0) 推荐(0) 编辑
摘要:环境 Rust 1.55.0 VSCode 1.59.1 概念 参考:https://doc.rust-lang.org/stable/rust-by-example/primitives/tuples.html 以 reverse 函数作为样板,写一个 transpose 函数,它可以接受一个 M 阅读全文
posted @ 2021-11-30 22:53 jiangbo4444 阅读(253) 评论(1) 推荐(0) 编辑
摘要:环境 Rust 1.55.0 VSCode 1.59.1 概念 参考:https://doc.rust-lang.org/stable/rust-by-example/primitives/tuples.html 给 Matrix 结构体 加上 fmt::Display trait,这样当你从 De 阅读全文
posted @ 2021-11-30 22:51 jiangbo4444 阅读(116) 评论(0) 推荐(0) 编辑
摘要:环境 Rust 1.54.0 VSCode 1.59.1 概念 元组(Tuple)是一种组合类型,使用小括号来表示,其中每个值的类型可以不相同。 示例 类型申明 Rust 中定义的变量如果不使用的话,可以用下划线开头,就不会有警告信息。 fn main() { let _x = (1, 1.2, t 阅读全文
posted @ 2021-11-30 22:42 jiangbo4444 阅读(274) 评论(0) 推荐(0) 编辑
摘要:环境 Rust 1.54.0 VSCode 1.59.1 概念 数组(array)是一组拥有相同类型 T 的对象的集合,在内存中是连续存储的。 数组使用中括号 [] 来创建,且它们的大小在编译时会被确定。 数组的类型标记为 [T; size],T 为元素的类型,size 表示数组的大小。 示例 类型 阅读全文
posted @ 2021-11-30 22:41 jiangbo4444 阅读(253) 评论(0) 推荐(0) 编辑
摘要:环境 Rust 1.54.0 VSCode 1.59.1 概念 布尔类型有两种, true 和 false。 示例 类型申明 fn main() { let x = false; let y: bool = true; println!("x = {}, y = {}", x, y); } 布尔运算 阅读全文
posted @ 2021-11-30 22:39 jiangbo4444 阅读(69) 评论(0) 推荐(0) 编辑
摘要:环境 Rust 1.54.0 VSCode 1.59.1 概念 浮点类型有 f32 和 f64 两种,四则运算也适用于浮点类型。 默认类型是 f64,因为在现代 CPU 中,它与 f32 速度几乎一样,不过精度更高。 示例 f32 fn main() { let x: f32 = 6.4; let 阅读全文
posted @ 2021-11-30 22:38 jiangbo4444 阅读(140) 评论(0) 推荐(0) 编辑
摘要:环境 Rust 1.54.0 VSCode 1.59.1 概念 字符类型使用 char 来表示,用单引号来定义,一个字符占用四个字节。 示例 类型申明 fn main() { let c = 'z'; let z = 'ℤ'; let heart_eyed_cat = '😻'; } 总结 介绍了 阅读全文
posted @ 2021-11-30 22:36 jiangbo4444 阅读(129) 评论(0) 推荐(0) 编辑
摘要:环境 Rust 1.54.0 VSCode 1.59.1 概念 Rust 中的整型可以分为有符号的整型和无符号的整型,有如下的类型: 长度 有符号 无符号 8-bit i8 u8 16-bit i16 u16 32-bit i32 u32 64-bit i64 u64 128-bit i128 u1 阅读全文
posted @ 2021-11-30 22:35 jiangbo4444 阅读(155) 评论(0) 推荐(0) 编辑
摘要:环境 Rust 1.55.0 VSCode 1.59.1 概念 格式化练习,参考资料:https://doc.rust-lang.org/stable/rust-by-example/hello/print/print_display/testcase_list.html 示例 use std::f 阅读全文
posted @ 2021-11-30 22:33 jiangbo4444 阅读(142) 评论(0) 推荐(0) 编辑
摘要:环境 Rust 1.55.0 VSCode 1.59.1 概念 Display 输出使用 {} 来进行打印,Display 主要是面向用户的输出。 如果要实现 display 输出,需要实现 std::fmt::Display 这个 trait。 trait 可以先简单理解为其它编程语言中的接口 示 阅读全文
posted @ 2021-11-30 22:32 jiangbo4444 阅读(813) 评论(0) 推荐(0) 编辑
摘要:环境 Rust 1.55.0 VSCode 1.59.1 概念 Debug 输出使用 {:?} 来进行打印,所有的标准库中的类型,都可以使用 debug 来输出。 Debug 主要是面向程序的输出,一般来说,使用 derive 来自动实现 Debug,使用 {:#?} 来进行美化打印。 如果要实现 阅读全文
posted @ 2021-11-30 22:31 jiangbo4444 阅读(672) 评论(0) 推荐(0) 编辑
摘要:环境 Rust 1.55.0 VSCode 1.59.1 概念 格式化练习,参考资料:https://doc.rust-lang.org/stable/rust-by-example/hello/print/fmt.html 示例 use std::fmt::{self, Display, Form 阅读全文
posted @ 2021-11-30 22:30 jiangbo4444 阅读(222) 评论(0) 推荐(0) 编辑
摘要:环境 Rust 1.54.0 VSCode 1.59.1 参考文档 https://doc.rust-lang.org/stable/rust-by-example/hello/print.html 示例 其中 println! 和 print! 类似,只是多 ln 的会多一个换行,会输出到标准输出 阅读全文
posted @ 2021-11-30 22:29 jiangbo4444 阅读(395) 评论(0) 推荐(0) 编辑
摘要:环境 Rust 1.54.0 VSCode 1.59.1 概念 参考:https://doc.rust-lang.org/stable/rust-by-example/hello/comment.html 文档注释(doc comments):文档注释会对外公开,使用者一般在使用之前,会进行阅读。 阅读全文
posted @ 2021-11-30 22:27 jiangbo4444 阅读(405) 评论(0) 推荐(0) 编辑
摘要:环境 Rust 1.54.0 VSCode 1.59.1 概念 参考:https://doc.rust-lang.org/stable/rust-by-example/hello/comment.html 文档注释(doc comments):文档注释会对外公开,使用者一般在使用之前,会进行阅读。 阅读全文
posted @ 2021-11-30 22:25 jiangbo4444 阅读(370) 评论(0) 推荐(0) 编辑
摘要:环境 Rust 1.54.0 VSCode 1.59.1 概念 参考:https://doc.rust-lang.org/stable/rust-by-example/hello/comment.html 文档注释(doc comments):文档注释会对外公开,使用者一般在使用之前,会进行阅读。 阅读全文
posted @ 2021-11-30 22:24 jiangbo4444 阅读(250) 评论(0) 推荐(0) 编辑
摘要:环境 Rust 1.54.0 VSCode 1.59.1 概念 参考:https://doc.rust-lang.org/stable/rust-by-example/hello/comment.html 块注释(block comments):当代码逻辑很复杂,需要额外说明时,可以使用块注释来帮助 阅读全文
posted @ 2021-11-30 22:20 jiangbo4444 阅读(337) 评论(0) 推荐(0) 编辑
摘要:环境 Rust 1.54.0 VSCode 1.59.1 概念 参考:https://doc.rust-lang.org/stable/rust-by-example/hello/comment.html 行注释(line comments):当代码逻辑很复杂,需要额外说明时,可以使用行注释来帮助人 阅读全文
posted @ 2021-11-30 22:19 jiangbo4444 阅读(114) 评论(0) 推荐(0) 编辑
摘要:环境 Windows 10 下载 rust-init 进入官网的下载页面:https://www.rust-lang.org/tools/install 根据 32 还是 64 位系统选择下载不同的 exe 文件,下载完成后双击运行。 安装 Rust 前置条件说明 默认情况,Rust 依赖 C++ 阅读全文
posted @ 2021-11-30 22:16 jiangbo4444 阅读(3786) 评论(0) 推荐(0) 编辑

上一页 1 ··· 8 9 10 11 12 13 下一页