About this Crate
- How to Create and Publish an Own Crate
- How to Use an Own Crate
- How te develop the unit tests
- How te develop the integration tests
- How te develop the unit tests for private codes
- See Code
Sections
I crate a workspace
mkdir workpsaces && cd workpsaces
mkdir hello-world && cd hello-world
touch Cargo.toml
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
cargo init --name hello_exercism --lib
2 develop the crate source and test codes for folder '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 develop the example codes
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
cargo login <token>
cargo test
cargo package
cargo publish
III use the crate
1 create the default Bin
mkdir bin-hello && cd bin-hello
cargo init --name bin-hello --bin
2 configure the file Cargo.toml
echo 'hello_exercism = "0.4.0"' >> Cargo.toml
3 edit the rust file main.rs
use hello_exercism;
fn main () {
println!("{}",hello_exercism::hello());
assert_eq!("Hello, World!", hello_exercism::hello());
}
4 run the Bin program
cargo run main
IV create the crate doc in local version
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/