- Rust Programming Cookbook
- Claus Matzinger
- 191字
- 2021-06-24 12:27:43
Getting ready
This time, we are going to create two projects: one that offers some type of function and another one to use it. Therefore, use cargo to create both projects: cargo new rust-pilib --lib and cargo new pi-estimator. The second command creates a binary executable so we can run the compilation result, while the former is a library (crate).
This recipe is going to create a small program that prints out estimations of pi () and rounds them to two decimal places. It's nothing fancy and easy for anyone to understand.
Naming crates is hard. The main repository ( https://crates.io/) is very permissive and has already seen name squatting (where people reserve names with the intent to sell them—think of names such as YouTube or Facebook, which would make nice API client names for these companies), and many crates are re-implementations of C libraries or wrap them. A good practice is to call the repository or directory rust-mycoolCwrapper and use mycoolCwrapper to name the crate itself. This way, only issues specific to your crate come in while the name is easy to guess in people's dependencies!
推薦閱讀
- Mobile Application Development:JavaScript Frameworks
- Python自動化運維快速入門(第2版)
- 深入理解Java7:核心技術與最佳實踐
- Backbone.js Blueprints
- Responsive Web Design by Example
- 從Excel到Python:用Python輕松處理Excel數據(第2版)
- 精通Linux(第2版)
- Swift語言實戰精講
- Nginx Lua開發實戰
- Unity 2D Game Development Cookbook
- Python圖形化編程(微課版)
- Principles of Strategic Data Science
- 邊玩邊學Scratch3.0少兒趣味編程
- Groovy 2 Cookbook
- Arduino Electronics Blueprints