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

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.

主站蜘蛛池模板: 军事| 翁牛特旗| 怀仁县| 乌什县| 武汉市| 双柏县| 昭苏县| 金平| 博乐市| 昌宁县| 云龙县| 岗巴县| 衡阳县| 眉山市| 锦屏县| 安徽省| 布尔津县| 新津县| 平顺县| 南阳市| 昆明市| 宣武区| 淄博市| 筠连县| 广灵县| 乌兰浩特市| 佛冈县| 龙南县| 安乡县| 缙云县| 苏尼特左旗| 云浮市| 建水县| 安徽省| 禄丰县| 溧水县| 海淀区| 常州市| 获嘉县| 治多县| 六安市|