- Rust Programming Cookbook
- Claus Matzinger
- 294字
- 2021-06-24 12:27:41
How it works...
Let's go through the code to understand the execution flow.
The initial snippet is generated when cargo new hello-world is executed in step 1. As a project of type binary, a main function is required and rustc will be looking for it. Upon calling cargo run, cargo orchestrates compilation (with rustc) and linking (msvc on Windows, cc on *nix) and runs the resultant binary via its entry point: the main function (step 5).
In the function we create in step 3, we write a series of print!/println!/eprintln! statements, which are Rust macros. These macros facilitate the writing to the standard output or standard error channels of a command-line application and include additional arguments. In fact, if arguments are missing, the compiler won't compile the program.
The various arguments and the template string are combined using formatters, a powerful way to add real variables to the output without the need of concatenations or similar workarounds. This will reduce the number of allocations, considerably improving performance and memory efficiency. There is a wide range of how to format data types; to understand it more deeply, check out Rust's excellent documentation (https://doc.rust-lang.org/std/fmt/).
The last step then shows the output that the various combinations produced.
We've successfully learned to work with the command line I/O. Now, let's move on to the next recipe.
- Fundamentals of Linux
- CockroachDB權(quán)威指南
- Power Up Your PowToon Studio Project
- 自己動(dòng)手寫Java虛擬機(jī)
- Learning RabbitMQ
- 數(shù)據(jù)庫系統(tǒng)原理及MySQL應(yīng)用教程
- Visual Basic程序設(shè)計(jì)教程
- Apache Mahout Clustering Designs
- 大數(shù)據(jù)分析與應(yīng)用實(shí)戰(zhàn):統(tǒng)計(jì)機(jī)器學(xué)習(xí)之?dāng)?shù)據(jù)導(dǎo)向編程
- iOS開發(fā)實(shí)戰(zhàn):從入門到上架App Store(第2版) (移動(dòng)開發(fā)叢書)
- 區(qū)塊鏈項(xiàng)目開發(fā)指南
- Vue.js光速入門及企業(yè)項(xiàng)目開發(fā)實(shí)戰(zhàn)
- Mastering Android Studio 3
- Python物理建模初學(xué)者指南(第2版)
- Access數(shù)據(jù)庫應(yīng)用教程(2010版)