Skip to content

Commit

Permalink
Adds docstring app
Browse files Browse the repository at this point in the history
  • Loading branch information
dr-saad-la committed Jul 20, 2024
1 parent 8fde113 commit ba159a3
Show file tree
Hide file tree
Showing 3 changed files with 77 additions and 0 deletions.
7 changes: 7 additions & 0 deletions code/01_starter/docstring/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions code/01_starter/docstring/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[package]
name = "docstring"
version = "0.1.0"
edition = "2021"

[dependencies]
64 changes: 64 additions & 0 deletions code/01_starter/docstring/src/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
//================================================================================
// By: Dr. Saad Laouadi
// Course: Rust Distilled
// Lesson: Documenting Code in Rust
//
// © copy-right: Dr. Saad Laouadi
//================================================================================

// Documentation in Rust
// =====================

// Outer Docstring
// ===============

/**
* This is a documentation comment in Rust.
* Documentation comments are used to generate API documentation.
* They start with `///` and can be used with markdown formatting.
*/

// To see the documentation run this command:
// ```cargo doc --open```

/// Adds two numbers and returns the result.
///
/// # Arguments
///
/// * `a` - The first number.
/// * `b` - The second number.
///
/// # Example
///
/// ```
/// let result = add(5, 3);
/// println!("The result is {}", result); // The result is 8
/// ```
fn add(a: i32, b: i32) -> i32 {
// Adding two numbers
a + b
}

//
fn main() {
// This statement is used only to print a banner to stdout
println!("{}", "*".repeat(52));
// Calling the add function with arguments 5 and 3
let result = add(5, 3);

// Printing the result to the console
println!("The result of adding 5 and 3 is: {}", result); // The result of adding 5 and 3 is: 8
println!("{}", "*".repeat(52));

// This attribute to silence the compiler warning about unused inline documentation
#[allow(unused_doc_comments)]
/// Inline documentation comment example
/// Here we demonstrate how to use documentation comments inline.
/// This can be useful for explaining specific parts of your code in detail.
///
/// ```rust
/// let example = "This is a documentation comment";
/// println!("{}", example);
/// ```
let _inline_doc_example = "Documentation comments can be used inline as well.";
}

0 comments on commit ba159a3

Please sign in to comment.