hello_exercism 0.4.3

how to create an own crate
Documentation

About this Crate

  • How to Create a Workspace
  • How to Create and Publish an Own Crate
  • How to Use an Own Crate
  • How te develop the unit tests with the folder 'tests'
  • How te develop the unit tests for private codes
  • How te develop the integration tests with the folder 'tests'
  • How te develop the integration tests with the folder 'src'
  • See Code

Sections

I crate a workspace

# 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 develop the crate

1 create the default crate

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

2 develop the crate source and test codes for folder 'tests'

  • Go to Crate Root Path
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 develop the example codes

  • Go to Crate Root Path
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 develop the crate source and test codes for folder '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 publish the own crate to crates.io

## run the follow commant at A time
cargo login <token>
## can repeat the follow commands
cargo test
## commit and push the codes
cargo package
cargo publish

III use the crate

1 create the default Bin

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

2 configure the file Cargo.toml

  • Go to Bin Root Path
echo 'hello_exercism = "0.4.0"' >> Cargo.toml

3 edit the rust file main.rs

  • Go to Bin Root Path
// vi src/main.rs
use hello_exercism;

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

4 run the Bin program

  • Go to Bin Root Path
cargo run main

IV create the crate doc in local version

  • Go to Crate Root Path
cargo doc --open --package hello_exercism

V create the crate doc in server version

  • github.com >> >> Setting >> Options >> GitHub Pages >> (INFO...)
  • Go to Crate Root Path
mkdir <REPOSITORY>/docs/<PROJECT_NAME>
cargo doc
cp -rf target/doc/.  <REPOSITORY>/docs/<PROJECT_NAME>/.
  • Example:
  • Go to Crate Root Path
mkdir -p ../../docs/hello-world
cargo doc
cp -rf target/doc/. ../../docs/hello-world/