官术网_书友最值得收藏!

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!
主站蜘蛛池模板: 怀柔区| 东乡县| 东港市| 聂荣县| 称多县| 曲麻莱县| 阜康市| 留坝县| 中卫市| 通渭县| 额敏县| 正定县| 平遥县| 博野县| 东乡族自治县| 云南省| 临邑县| 溧水县| 明水县| 香港 | 楚雄市| 昌黎县| 融水| 武威市| 会同县| 开鲁县| 洪湖市| 苏尼特右旗| 喀喇沁旗| 尉犁县| 云浮市| 天津市| 新沂市| 红安县| 阜新市| 张家界市| 五家渠市| 林甸县| 水富县| 都安| 固安县|