随笔分类 - Rust
摘要:在 C 中使用 Rust 函数主要通过 Rust 构建动态库,然后 C 使用该动态库来实现。 构建动态库 首先要创建一个动态库项目,使用命令 cargo new hello --lib。 我们需要指明库类型为动态库,在 Cargo.toml 文件中添加 [lib] name = "hello
阅读全文
摘要:本文中内容来自: Rust's Type System is Turing-Complete Smallfuck 语言 Smallfuck 是一门最小的图灵完备的编程语言, 其可以看成最基本的图灵机的一种变体, 其将计算机看成一条无限长的纸带, 纸带每一格存储 0 或 1, 存在一个指针指向纸带的某
阅读全文
摘要:异步编程在 Rust 中的地位非常高,很多 crate 尤其是多IO操作的都使用了 async/await. 首先弄清楚异步编程的几个基本概念: Future Future 代表一个可在未来某个时候获取返回值的 task,为了获取这个 task 的执行状况,Future 提供了一个函数用于判断该 t
阅读全文
摘要:Rust Trick 之 Trait Object 转换为 Struct 在C/C++里面,trait通常是以父类的形式出现的,父类转换为子类通常直接可以通过指针类型的转换就可以完成,当然C++也可以通过cast完成。 在rust里面当然也可以一切通过raw pointer来完成,但是我觉得在rus
阅读全文
摘要:相信不少人和我一样初次接触Rust的模块系统时都会觉得难以理解,因为与之前学的编程语言的文件导入不一样。个人觉得C/C++系的导入是最容易理解的,直接将头文件中定义的内容include后就可以使用其中的内容。 但是Rust不一样,Rust使用模块 来管理所有的权限和导入问题。在创建了一个微型项目测试
阅读全文
摘要:Handling concurrent programming safely and efficiently is another of Rust's major goals. For simplicity's sake, we'll refer to many of the problems as
阅读全文
摘要:Unsafe Rust So far, you can see that Rust has a strict memory safety guarantee at compile time. However, sometimes this safety guarantee can be annoyi
阅读全文
摘要:A pointer is a general concept for a variable contains an address in memory. Smart pointers are data structures that not only act like a pointer but a
阅读全文
摘要:How to Write Tests Tests are functions that verify that the non test code is functioning in the expected manner. The bodies of test functions typicall
阅读全文
摘要:In Rust, generics is a tool for establishing abstract stand ins for concrete types or other properties. When we're writing code, we can express the be
阅读全文
摘要:Reference and Borrowing In Rust, we use sign to refer a variable, so as in C++. Reference can be used as a constant parameter passed to functions, whi
阅读全文
摘要:Error handling requires you to acknowledge the possibility of an error and take some action before your code crashes. This requirement makes your prog
阅读全文
摘要:Storing Lists of Values with Vectors Vector The first collection type we'll look at is , as known as a Vector . Vector allows you to store more than o
阅读全文
摘要:Packages and Crates A crate is a binary or library. The crate root is a source file that the Rust Compiler starts from and makes up the root module of
阅读全文
摘要:Defining and Instantiating Structs Rust allows us to use structs to organize a group of related data. We use such syntax to define a struct: To instan
阅读全文
摘要:Rust所有权 今天本来随便看看rust的语法,但是看到rust的所有权时觉得挺新颖的,特意做做笔记。 1. 所有权规则 rust中的每个值都有一个变量,称其为所有者 一次只能有一个所有者 当所有者不在程序运行范围时,该值会被删除 2. 内存分配 rust同样适用堆来动态分配内存,但相比C/C++,
阅读全文