子项目:仓库程序项目bin-hello

  在共享篋hello_exercism发布以后,Cargo项目仓库程序可以以独立的Cargo项目使用共享篋,且开发应用和检查代码。一般情况下。用户使用共享篋是以这种项目形式出现的。

  这个仓库程序项目介绍了一种方法,在一个可执行的软件篋里,存在多个独立的可执行程序。

学习内容

  • 阐述项目仓库程序开发方法
  • 理解项目仓库程序代码

篇目

  1. 项目配置文件Cargo.toml
  2. 主程序文件main.rs
  3. 集成测试文件i_hello.rs

项目配置文件Cargo.toml

  下面文件Cargo.toml里,与项目关系最大的一行代码是最后一行代码。这行代码说明了所使用的共享篋,包括共享篋名称和版本号。

[package]
name = "bin-hello"
version = "0.5.3"
authors = ["cnruby <gudao.luo@gmail.com>"]
edition = "2018"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
# https://crates.io/crates/hello_exercism
# change the follow version to current version
hello_exercism = "0.5.3"

主程序文件src/bin/hello.rs

  下面主程序文件main.rs与前面项目bin-local-hello完全是一样的。

fn main () {
    println!("{}",hello_exercism::hello());
}

  执行上面程序的命令及其结果,如下所示:

$ cargo run -q
Hallo, Welt!
Hello, World!

主程序文件src/bin/hallo.rs

fn main () {
    assert_eq!("Hello, World!", hello_exercism::hello());
}

集成测试文件i_hello.rs

  下面的集成测试文件i_hello.rs与前面项目bin-local-hello完全是一样的。


# #![allow(unused_variables)]
#fn main() {
#[test]
fn test_hello_world() {
    assert_eq!("Hello, World!", hello_exercism::hello());
}
#}