- Rust Quick Start Guide
- Daniel Arbuckle
- 160字
- 2021-06-10 19:46:01
Automatically generated source files
When creating an executable program, cargo adds a file called main.rs to our project as it is created. For a newly created library, it instead adds lib.rs. In either case, that file is the entry point for the whole project.
Let's take a look at the boilerplate main.rs file:
fn main() {
println!("Hello, world!");
}
Simple enough, right? Cargo's default program is a Rust version of the classic hello world program, which has been re-implemented countless times by new programmers in every conceivable programming language.
If we look at a new library's lib.rs file, things are a little more interesting:
#[cfg(test)]
mod tests {
#[test]
fn it_works() {
assert_eq!(2 + 2, 4);
}
}
Instead of having a main function, which all executable programs need because they need a place to start, the library boilerplate includes a framework for automated tests and a single test that confirms that 2 + 2 = 4.
- Spring Boot 2實戰之旅
- Python概率統計
- Twilio Best Practices
- PostgreSQL技術內幕:事務處理深度探索
- Python進階編程:編寫更高效、優雅的Python代碼
- 老“碼”識途
- STM32F0實戰:基于HAL庫開發
- Building Minecraft Server Modifications
- Mastering KnockoutJS
- TypeScript項目開發實戰
- 微服務從小白到專家:Spring Cloud和Kubernetes實戰
- MINECRAFT編程:使用Python語言玩轉我的世界
- 3ds Max印象 電視欄目包裝動畫與特效制作
- Mastering Apache Camel
- 視窗軟件設計和開發自動化:可視化D++語言