hello_exercism

Crates.iohello_exercism
lib.rshello_exercism
version0.5.5
sourcesrc
created_at2019-09-21 10:43:03.402327
updated_at2019-10-07 05:52:38.862546
descriptionhow to create an own crate
homepagehttps://crates.io/crates/hello_exercism
repositoryhttps://github.com/cnruby/learn-rust-by-crates/tree/master/hello-world
max_upload_size
id166458
size101,686
Gudao Luo (cnruby)

documentation

https://cnruby.github.io/learn-rust-by-crates/hello-world/hello_exercism/

README

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

The Rust Language Tool: Cargo

About this Crate hello_exercism

  • 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'

Table of Contents

I. create 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 in github.com 
cargo package
cargo publish
## change the release github.com

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/
Commit count: 0

cargo fmt