44 个版本 (4 个重大更新)

0.5.5 2019 年 10 月 7 日
0.5.4 2019 年 10 月 7 日
0.4.10 2019 年 10 月 4 日
0.4.1 2019 年 9 月 29 日
0.1.9 2019 年 9 月 21 日

#328测试

Download history 1/week @ 2024-02-29 1/week @ 2024-03-07 98/week @ 2024-03-28 8/week @ 2024-04-04

每月 78 次下载

MIT/Apache

89KB
53

Minimum rustc version The Crate hello_exercism Code Build Status on appveyor.com GitHub issues Twitter URL

Rust 语言工具: Cargo

关于此包 hello_exercism

  • 如何创建工作空间
  • 如何创建和发布自研包
  • 如何使用自研包
  • 如何使用 'tests' 文件夹开发单元测试
  • 如何为私有代码开发单元测试
  • 如何使用 'tests' 文件夹开发集成测试
  • 如何使用 'src' 文件夹开发集成测试

目录

I. 创建工作空间

# create a workspaces
mkdir workpsaces && cd workpsaces
# create a workspace 'hello-world'
mkdir hello-world && cd hello-world
# create a configration for the workspace
touch Cargo.toml
# four crates for this workspace
# the follow lines is ONE command
echo '[workspace]
members = ["lib-hello", "bin-hello", "bin-local-hello", "lib-extern"]' >> Cargo.toml

II. 开发包

1. 创建默认包

mkdir lib-hello && cd lib-hello
# this is Crate Root Path
cargo init --name hello_exercism --lib

2. 开发包源代码和 'tests' 文件夹的测试代码

  • 转到包根目录
vi Cargo.toml
vi src/lib.rs
mkdir tests
touch tests/u_hello.rs
vi tests/u_hello.rs
touch tests/i_hello.rs
vi tests/i_hello.rs
cargo test

3. 开发示例代码

  • 转到包根目录
mkdir examples
touch examples/u_hello.rs
vi examples/u_hello.rs
cargo run --example u_hello
touch examples/i_hello.rs
vi examples/i_hello.rs
cargo run --example i_hello

4. 开发包源代码和 'src' 文件夹的测试代码

vi src/lib.rs
mkdir -p src/integration_tests
touch src/integration_tests/mod.rs
vi src/integration_tests/mod.rs
touch src/integration_tests/i_hello.rs
vi src/integration_tests/i_hello.rs
mkdir -p src/private_tests
touch src/private_tests/mod.rs
vi src/private_tests/mod.rs
touch src/private_tests/owned_hello.rs
vi src/private_tests/owned_hello.rs
cargo test

5. 将自研包发布到 crates.io

## run the follow commant at A time
cargo login <token>
## can repeat the follow commands
cargo test
## commit and push the codes in github.com 
cargo package
cargo publish
## change the release github.com

III. 使用包

1. 创建默认二进制文件

mkdir bin-hello && cd bin-hello
# this is Bin Root Path
cargo init --name bin-hello --bin

2. 配置 Cargo.toml 文件

  • 转到二进制文件根目录
echo 'hello_exercism = "0.4.0"' >> Cargo.toml

3. 编辑 rust 文件 main.rs

  • 转到二进制文件根目录
// vi src/main.rs
use hello_exercism;

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

4. 运行二进制程序

  • 转到二进制文件根目录
cargo run main

IV. 在本地版本中创建包文档

  • 转到包根目录
cargo doc --open --package hello_exercism

V. 在服务器版本中创建包文档

  • github.com >> >> 设置 >> 选项 >> GitHub Pages >> (INFO...)
  • 转到包根目录
mkdir <REPOSITORY>/docs/<PROJECT_NAME>
cargo doc
cp -rf target/doc/.  <REPOSITORY>/docs/<PROJECT_NAME>/.
  • 示例
  • 转到包根目录
mkdir -p ../../docs/hello-world
cargo doc
cp -rf target/doc/. ../../docs/hello-world/

依赖