cargo fmt
This commit is contained in:
@@ -41,7 +41,11 @@ fn main() {
|
||||
// Hint: .to_uppercase() is a method on `str` which returns a String
|
||||
|
||||
let words = vec!["autobot", "beach", "car", "decepticon", "energon", "frothy"];
|
||||
let transformed = words.into_iter().filter(|w| !w.contains("h")).map(|w| w.to_uppercase()).collect::<Vec<String>>();
|
||||
let transformed = words
|
||||
.into_iter()
|
||||
.filter(|w| !w.contains("h"))
|
||||
.map(|w| w.to_uppercase())
|
||||
.collect::<Vec<String>>();
|
||||
println!("Transformed: {:?}", transformed);
|
||||
|
||||
// Challenge:
|
||||
|
||||
@@ -23,9 +23,9 @@
|
||||
// - Document the "orangeness" field, explaining that it is a number from 8 to 27
|
||||
|
||||
/// Big orange thing
|
||||
///
|
||||
///
|
||||
/// # Recipes
|
||||
///
|
||||
///
|
||||
/// Recipes will be coming soon.
|
||||
pub struct Pumpkin {
|
||||
/// `roundness` is a percentage that describes how round the pumpkin is.
|
||||
|
||||
@@ -24,7 +24,7 @@ pub enum DolphinError {
|
||||
#[error("The dolphin is too young")]
|
||||
TooYoung,
|
||||
#[error("The dolphin's name is too long and annoying to say")]
|
||||
LongName
|
||||
LongName,
|
||||
}
|
||||
|
||||
pub struct Dolphin {
|
||||
|
||||
@@ -3,14 +3,12 @@
|
||||
use aquarium::Dolphin;
|
||||
// Silence some warnings so they don't distract from the exercise.
|
||||
#[allow(clippy::vec_init_then_push)]
|
||||
|
||||
// (You already did #1 in lib.rs, right?)
|
||||
//
|
||||
// 2a. Uncomment and finish the play_time function below
|
||||
// - Bring anyhow::Result into scope with a `use` statement
|
||||
// - Have the play_time function return a `Result<Vec<String>>`. The vector of Strings will
|
||||
// represent successful outcomes of various dolphin tricks.
|
||||
|
||||
use anyhow::Result;
|
||||
|
||||
fn play_time(dolphin: &Dolphin) -> Result<Vec<String>> {
|
||||
@@ -18,10 +16,10 @@ fn play_time(dolphin: &Dolphin) -> Result<Vec<String>> {
|
||||
// 2b. Call the .say_your_name() method on `dolphin`, use `?` to unwrap the value, and push
|
||||
// the value onto the `responses` vector.
|
||||
//
|
||||
let response = dolphin.say_your_name()?; // this can be done with an intermediate variable...
|
||||
let response = dolphin.say_your_name()?; // this can be done with an intermediate variable...
|
||||
responses.push(response); // ...or all on one line. Either way is fine!
|
||||
//
|
||||
// 2c. Do the same thing as #2b for the .flip() method
|
||||
//
|
||||
// 2c. Do the same thing as #2b for the .flip() method
|
||||
responses.push(dolphin.flip()?);
|
||||
//
|
||||
// 2d. Do the same thing as #2b for the .shake_hands() method
|
||||
@@ -56,7 +54,7 @@ fn main() -> Result<()> {
|
||||
for dolphin in &dolphins {
|
||||
// Challenge: Change main() so that it returns a Result, and instead of handling the error
|
||||
// that play_time returns, use the try (?) operator to only handle the success condition.
|
||||
//
|
||||
//
|
||||
// If done correctly, the output of the program will become much shorter. Since play_time
|
||||
// returns an Err variant the first time it is called, the try operator will return it from
|
||||
// main(), which will end the program at the first error. anyhow's Result will take care of
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
//
|
||||
// Hint: You need to update Cargo.toml to add the `log` dependency, first.
|
||||
|
||||
use log::{error, warn, info, debug, trace};
|
||||
use log::{debug, error, info, trace, warn};
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct Frog {
|
||||
|
||||
@@ -2,7 +2,9 @@ use criterion::{black_box, criterion_group, criterion_main, Criterion};
|
||||
use testing::sploosh;
|
||||
|
||||
pub fn sploosh_benchmark(c: &mut Criterion) {
|
||||
c.bench_function("sploosh", |b| b.iter(|| sploosh(black_box(8), black_box(9), black_box(10))));
|
||||
c.bench_function("sploosh", |b| {
|
||||
b.iter(|| sploosh(black_box(8), black_box(9), black_box(10)))
|
||||
});
|
||||
}
|
||||
|
||||
criterion_group!(benches, sploosh_benchmark);
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
use testing::{sploosh, splish};
|
||||
use testing::{splish, sploosh};
|
||||
|
||||
#[test]
|
||||
pub fn test_sploosh_splish() {
|
||||
|
||||
@@ -113,13 +113,7 @@ fn main() {
|
||||
}
|
||||
});
|
||||
|
||||
for number in vec![
|
||||
1,
|
||||
2,
|
||||
3,
|
||||
4,
|
||||
5,
|
||||
] {
|
||||
for number in vec![1, 2, 3, 4, 5] {
|
||||
println!("NUMBER: {}", number);
|
||||
let _ = tx.send(number);
|
||||
}
|
||||
|
||||
@@ -17,7 +17,7 @@ impl Default for Party {
|
||||
Self {
|
||||
at_restaurant: true,
|
||||
num_people: 8,
|
||||
cake: Cake::Chocolate
|
||||
cake: Cake::Chocolate,
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -110,7 +110,10 @@ fn main() {
|
||||
// consuming it. Change the code above to pass in a &party. Then uncomment and run the code
|
||||
// below. After all, you want to smell your cake and eat it, too!
|
||||
|
||||
println!("Yum! I'm eating this cake: {:?}. Oops, I dropped it on the floor.", party.cake);
|
||||
println!(
|
||||
"Yum! I'm eating this cake: {:?}. Oops, I dropped it on the floor.",
|
||||
party.cake
|
||||
);
|
||||
}
|
||||
|
||||
pub fn admire_cake(cake: Cake) {
|
||||
|
||||
Reference in New Issue
Block a user