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

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.

主站蜘蛛池模板: 定南县| 苏尼特右旗| 抚顺县| 澳门| 和平县| 华阴市| 汨罗市| 库尔勒市| 溧水县| 正蓝旗| 馆陶县| 福鼎市| 革吉县| 新疆| 康马县| 宝坻区| 拉孜县| 福鼎市| 三江| 松江区| 米脂县| 邓州市| 湘西| 城市| 临湘市| 和政县| 沙洋县| 临夏市| 武夷山市| 许昌市| 宁化县| 普宁市| 义乌市| 砀山县| 望奎县| 云浮市| 泰州市| 韶山市| 商都县| 封丘县| 五峰|