Loading rust_02_basics...
rustup doc
rustup doc --book
rustup doc --rust-by-example
rustup doc --std
rustup doc --std 'std::vec::Vec'
rustup doc --reference
rustup doc --cargo
rustup doc --rustdoc
cargo new my_first_project
my_first_project ├── Cargo.toml └── src └── main.rs
cd my_first_project
code .
subl .
cargo build
cargo run
./target/debug/my_first_project
/tmp/cargo_target_${USER}/debug/my_first_project
${USER}représentant le nom de l'utilisateur)
cargo clean
/tmp/cargo_target_${USER}(avec
${USER}représentant le nom de l'utilisateur).
rustup doc --cargo“4.2.2. cargo build”
rustup doc --cargo“4.2.8. cargo run”
rustup doc --cargo“4.2.4. cargo clean”
#![deny(warnings)]
cargo clippy
"rust-analyzer.check.command": "clippy",
#![deny(warnings)]
fn main() { if true { println!("Hello, world!"); } else { println!("Hello, world!"); } }
#![deny(warnings)]
pub fn add( first_parameter: i32, second_parameter: i32, ) -> i32 { first_parameter + second_parameter }
pub fn multiply( first_parameter: i32, second_parameter: i32, ) -> i32 { first_parameter * second_parameter }
#![deny(warnings)]
use my_first_project::{add, multiply};
fn main() { println!("Hello, world!"); let a = 10; let b = 20; let add_result = add(a, b); println!("add_result = {}", add_result); let multiply_result = multiply(a, b); println!("multiply_result = {}", multiply_result); }
cargo doc --no-deps
firefox target/doc/my_first_project/index.html
firefox /tmp/cargo_target_${USER}/doc/my_first_project/index.html
${USER}représentant le nom de l'utilisateur).
/// Returns the sum of two integers. /// /// This function takes two integers as parameters, computes their sum, /// then provides this sum as the result.
#![deny(warnings)]déjà présente :
#![warn(missing_docs)]
//! A trivial crate to begin with.
rustup doc --rustdoc“4. How to write documentation”
rustup doc --rust-by-example“24.1. Documentation”
rustup doc --cargo“4.2.5. cargo doc”
/// /// # Examples /// ``` /// use my_first_project::add; /// /// let r = add(10, 20); /// assert_eq!(r, 30); /// ```
cargo test
//! //! # Examples //! ``` //! use my_first_project::{add, multiply}; //! //! let r1 = add(10, 20); //! let r2 = multiply(r1, 5); //! assert_eq!(r2, 150); //! ```
use my_first_project::{add, multiply};
#[test] fn my_integration_test_1() { let r1 = add(10, 20); let r2 = multiply(r1, 5); assert_eq!(r2, 150); }
#[test] fn my_integration_test_2() { let r1 = add(10, 20); let r2 = add(40, 50); let r3 = multiply(r1, r2); assert_eq!(r3, 2700); }
rustup doc --rust-by-example“21.1. Unit testing”.
rustup doc --rustdoc“4.4. Documentation tests”
rustup doc --rust-by-example“21.2. Documentation testing”
rustup doc --rust-by-example“21.3. Integration testing”
rustup doc --cargo“4.2.11. cargo test”
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#![deny(warnings)] #![warn(missing_docs)]
//! A trivial crate to begin with. //! //! # Examples //! ``` //! use my_first_project::{add, multiply}; //! //! let r1 = add(10, 20); //! let r2 = multiply(r1, 5); //! assert_eq!(r2, 150); //! ```
/// Returns the sum of two integers. /// /// This function takes two integers as parameters, computes their sum, /// then provides this sum as the result. /// /// # Examples /// ``` /// use my_first_project::add; /// /// let r = add(10, 20); /// assert_eq!(r, 30); /// ``` pub fn add( first_parameter: i32, second_parameter: i32, ) -> i32 { first_parameter + second_parameter }
/// Returns the product of two integers. /// /// This function takes two integers as parameters, computes their product, /// then provides this product as the result. /// /// # Examples /// ``` /// use my_first_project::multiply; /// /// let r = multiply(10, 20); /// assert_eq!(r, 200); /// ``` pub fn multiply( first_parameter: i32, second_parameter: i32, ) -> i32 { first_parameter * second_parameter }
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#![deny(warnings)]
use my_first_project::{add, multiply};
fn main() { println!("Hello, world!"); let a = 10; let b = 20; let add_result = add(a, b); println!("add_result = {}", add_result); let multiply_result = multiply(a, b); println!("multiply_result = {}", multiply_result); }
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#![deny(warnings)]
use my_first_project::{add, multiply};
#[test] fn my_integration_test_1() { let r1 = add(10, 20); let r2 = multiply(r1, 5); assert_eq!(r2, 150); }
#[test] fn my_integration_test_2() { let r1 = add(10, 20); let r2 = add(40, 50); let r3 = multiply(r1, r2); assert_eq!(r3, 2700); }
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~