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

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.

主站蜘蛛池模板: 芦溪县| 那坡县| 雅江县| 自治县| 吉安市| 吐鲁番市| 奉节县| 嘉义市| 叙永县| 英超| 新乡县| 郴州市| 双牌县| 南岸区| 东阳市| 雷山县| 北川| 通河县| 东丽区| 北票市| 霍州市| 板桥市| 拜城县| 扎囊县| 登封市| 江都市| 汉沽区| 崇州市| 天长市| 鱼台县| 绥中县| 南投县| 清远市| 扬中市| 鄂温| 德兴市| 吉木萨尔县| 墨脱县| 额尔古纳市| 镇安县| 寿阳县|