- Rust Programming By Example
- Guillaume Gomez Antoni Boucher
- 393字
- 2021-07-02 19:12:54
Getting to know Rust
Rust is a system programming language developed by Mozilla, whose version 1.0 appeared in 2015. A system language means that you have control over the memory used by the program—you decide whether you want to allocate the memory on the stack or the heap, and when the memory is freed. But don't worry; in Rust, the compiler is very helpful and prevents you from making the many mistakes you can make in C and C++ that lead to segmentation faults. A segmentation fault arises when the programmer tries to access some memory that is not accessible to its process. Memory unsafety leads to bugs and security flaws.
Moreover, the compiler is smart enough to know where to insert the memory deallocation instructions so that you don't need to manually free your memory, all of that without a garbage collector, which is one of its greatest features. Since Rust is safe and fast, it is the perfect candidate for writing operating systems, embedded programs, servers, and games, but you can also use it to develop desktop applications and websites. A great example of this power is the Servo web engine, also developed by Mozilla.
Rust is multi-paradigm: it can be used in an imperative or functional way and you can even write concurrent applications safely. It is statically typed, meaning that every type must be known at compile time, but since it uses type inference, we can omit the type for most local variables. It is also strongly typed, which means that its type system prevents the programmer from some kinds of errors, such as using the wrong type for a function parameter. And Rust is very good at writing concurrent software because it prevents data races, which is concurrent access to a variable where one is a write; this is an undefined behavior in other languages. One thing to remember when reading this book is that Rust prevents you from shooting yourself in the foot. For instance, Rust doesn't have:
- null pointers
- data races
- use after free
- use before initialization
- goto
- automatic coercion of Boolean, numbers and enumerations
Also, Rust helps to prevent memory leaks. However, all of this is possible with unsafe code, which is explained in Chapter 3, Events and Basic Game Mechanisms.
Without further ado, let's install the tools we'll need throughout the book.
- 情報學與信息管理的主戰場:北京大學情報學與信息管理論壇文集
- 科學普及組織活動讀本
- 北大中文系第一課
- 面向青少年的博物館教育(上下卷)
- 國外圖書館動漫資源建設與服務
- 高校圖書館閱讀推廣與宣傳促進研究
- 檔案檢索: 理論與方法
- 地方政府數字檔案集中管理模式研究(國家社會科學基金項目成果)
- Practical Industrial Internet of Things Security
- 校勘學釋例(中國文化叢書·經典隨行)
- Rust Programming By Example
- 檔案修復與歷史資料的數字化:第六屆東亞史料研究編纂機構聯席會議論文集
- 近代中國的學術與藏書
- 圖書館學散論:科學網圖謀博客精粹
- 圖書館保障弱勢群體公共信息獲取權益的對策研究