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

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!
主站蜘蛛池模板: 富源县| 岳西县| 治多县| 塘沽区| 石台县| 密云县| 武隆县| 突泉县| 普宁市| 酒泉市| 德兴市| 凤山县| 垦利县| 黔西县| 三原县| 拜城县| 福鼎市| 乳山市| 乌鲁木齐市| 巴里| 同仁县| 九江市| 莆田市| 义马市| 仙桃市| 龙川县| 滨海县| 盱眙县| 滦南县| 灵武市| 南部县| 平乐县| 厦门市| 西青区| 巫山县| 忻城县| 项城市| 叙永县| 晋州市| 兴宁市| 赤城县|