docs exercise

This commit is contained in:
Nathan Stocks
2021-06-13 00:08:55 -06:00
parent c63dbe2f57
commit c1d451049d
5 changed files with 54 additions and 7 deletions

View File

@@ -1,9 +1,10 @@
[workspace] [workspace]
members = [ members = [
"examples/cafeteria", "example/cafeteria",
"examples/hello", "example/hello",
"examples/kitchen", "example/kitchen",
"examples/puzzle_game", "example/puzzle_game",
"examples/puzzles", "example/puzzles",
"exercises/idiomatic" "exercise/idiomatic",
"exercise/docs"
] ]

7
exercise/docs/Cargo.toml Normal file
View File

@@ -0,0 +1,7 @@
[package]
name = "docs"
version = "0.1.0"
authors = ["Nathan Stocks <nathan@agileperception.com>"]
edition = "2018"
[dependencies]

35
exercise/docs/src/lib.rs Normal file
View File

@@ -0,0 +1,35 @@
// 1. Thank you for volunteering to document our pumpkin library! Let's start by grabbing the first
// paragraph from https://en.wikipedia.org/wiki/Pumpkin and pasting it as our module-level
// documentation. Hint: Use inner-documentation comments.
//
// Once you've got the documentation here, run `cargo doc --no-deps --open` and take a look!
// 2. What about an image!? Add an image of a pumpkin to the end of the module-level documentation.
// The markdown format is ![some alt text](https://url-to-the-image.png)
// Here's the image to link to: https://upload.wikimedia.org/wikipedia/commons/thumb/5/5c/FrenchMarketPumpkinsB.jpg/700px-FrenchMarketPumpkinsB.jpg
// 3. Document the Pumpkin struct.
// - The description on the index page should be "Big orange thing"
// - Make a section header called "Recipes"
// - Explain that recipes will be coming soon.
// - Explain that "roundness" is a percentage
// - Explain that "orangeness" is a number from 8 to 27
pub struct Pumpkin {
pub roundness: f32,
pub orangeness: i32,
}
// 4. Explain that if you smash the pumpkin, it will be gone. Then it can't be used for pie. :'-(
impl Pumpkin {
pub fn smash(self) {}
}
// 5. Document that BURNT_ORANGE is for the "orangeness" field in the Pumpkin struct.
// - Link to the Pumpkin struct in your description
pub const BURNT_ORANGE: i32 = 13;
// Challenge: Move the Pumpkin struct's documentation *inside* of the struct definition. Can you
// see why that might not be the ideal approach?

View File

@@ -0,0 +1,4 @@
/// The exercise is in lib.rs this time!!!
fn main() {
println!("Go look in lib.rs ;-)");
}

View File

@@ -8,7 +8,7 @@
// Challenge: Clippy doesn't find *everything*. What else would you change to make this code better? // Challenge: Clippy doesn't find *everything*. What else would you change to make this code better?
const pi:f32=3.14159265358979323846; const pi:f32=3.14159265358979323846;
fn count_to_5()->i32{let mut foo =(0);loop{if{foo>pi as i32}{if(foo > 5){break;}}foo=foo+1;}return 5;} fn count_to_5()->i32{let mut foo =0;loop{if foo>pi as i32{if foo > 5{break;}}foo=foo+1;}return 5;}
fn main() { fn main() {
println!("I can count to {}", count_to_5()); println!("I can count to {}", count_to_5());
} }