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

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.

主站蜘蛛池模板: 泾阳县| 海盐县| 云和县| 海盐县| 额济纳旗| 凤台县| 米林县| 商都县| 博爱县| 中西区| 永安市| 台江县| 塘沽区| 潍坊市| 宜黄县| 隆昌县| 南郑县| 荥阳市| 天峻县| 松滋市| 翁源县| 清水县| 大同县| 云南省| 盐山县| 政和县| 沭阳县| 新郑市| 定远县| 扶绥县| 临沂市| 宁化县| 永年县| 华坪县| 石台县| 祁门县| 克拉玛依市| 华池县| 武陟县| 佛坪县| 清新县|