diff --git a/Cargo.toml b/Cargo.toml index 4397534..de0c66b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,9 +1,10 @@ [workspace] members = [ - "examples/cafeteria", - "examples/hello", - "examples/kitchen", - "examples/puzzle_game", - "examples/puzzles", - "exercises/idiomatic" + "example/cafeteria", + "example/hello", + "example/kitchen", + "example/puzzle_game", + "example/puzzles", + "exercise/idiomatic", + "exercise/docs" ] diff --git a/exercise/docs/Cargo.toml b/exercise/docs/Cargo.toml new file mode 100644 index 0000000..4a7deac --- /dev/null +++ b/exercise/docs/Cargo.toml @@ -0,0 +1,7 @@ +[package] +name = "docs" +version = "0.1.0" +authors = ["Nathan Stocks "] +edition = "2018" + +[dependencies] diff --git a/exercise/docs/src/lib.rs b/exercise/docs/src/lib.rs new file mode 100644 index 0000000..8f19682 --- /dev/null +++ b/exercise/docs/src/lib.rs @@ -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? diff --git a/exercise/docs/src/main.rs b/exercise/docs/src/main.rs new file mode 100644 index 0000000..9513bdf --- /dev/null +++ b/exercise/docs/src/main.rs @@ -0,0 +1,4 @@ +/// The exercise is in lib.rs this time!!! +fn main() { + println!("Go look in lib.rs ;-)"); +} diff --git a/exercise/idiomatic/src/main.rs b/exercise/idiomatic/src/main.rs index a57989c..63b2437 100644 --- a/exercise/idiomatic/src/main.rs +++ b/exercise/idiomatic/src/main.rs @@ -8,7 +8,7 @@ // Challenge: Clippy doesn't find *everything*. What else would you change to make this code better? 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() { println!("I can count to {}", count_to_5()); }