mirror of
https://github.com/rust-lang/rustlings.git
synced 2024-12-27 00:00:03 +03:00
Merge pull request #492 from etiennebarrie/rustfmt-on-exercises
chore: Run rustfmt on exercises
This commit is contained in:
commit
2d3816341e
|
@ -82,5 +82,4 @@ mod tests {
|
||||||
fn missing_name_and_invalid_age() {
|
fn missing_name_and_invalid_age() {
|
||||||
",one".parse::<Person>().unwrap();
|
",one".parse::<Person>().unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
// Basically, this is the same as From. The main difference is that this should return a Result type
|
// Basically, this is the same as From. The main difference is that this should return a Result type
|
||||||
// instead of the target type itself.
|
// instead of the target type itself.
|
||||||
// You can read more about it at https://doc.rust-lang.org/std/convert/trait.TryFrom.html
|
// You can read more about it at https://doc.rust-lang.org/std/convert/trait.TryFrom.html
|
||||||
use std::convert::{TryInto, TryFrom};
|
use std::convert::{TryFrom, TryInto};
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
struct Color {
|
struct Color {
|
||||||
|
|
|
@ -7,9 +7,7 @@
|
||||||
// I AM NOT DONE
|
// I AM NOT DONE
|
||||||
|
|
||||||
fn average(values: &[f64]) -> f64 {
|
fn average(values: &[f64]) -> f64 {
|
||||||
let total = values
|
let total = values.iter().fold(0.0, |a, b| a + b);
|
||||||
.iter()
|
|
||||||
.fold(0.0, |a, b| a + b);
|
|
||||||
total / values.len()
|
total / values.len()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -16,10 +16,10 @@ impl Message {
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let messages = [
|
let messages = [
|
||||||
Message::Move{ x: 10, y: 30 },
|
Message::Move { x: 10, y: 30 },
|
||||||
Message::Echo(String::from("hello world")),
|
Message::Echo(String::from("hello world")),
|
||||||
Message::ChangeColor(200, 255, 255),
|
Message::ChangeColor(200, 255, 255),
|
||||||
Message::Quit
|
Message::Quit,
|
||||||
];
|
];
|
||||||
|
|
||||||
for message in &messages {
|
for message in &messages {
|
||||||
|
|
|
@ -9,13 +9,13 @@ enum Message {
|
||||||
|
|
||||||
struct Point {
|
struct Point {
|
||||||
x: u8,
|
x: u8,
|
||||||
y: u8
|
y: u8,
|
||||||
}
|
}
|
||||||
|
|
||||||
struct State {
|
struct State {
|
||||||
color: (u8, u8, u8),
|
color: (u8, u8, u8),
|
||||||
position: Point,
|
position: Point,
|
||||||
quit: bool
|
quit: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl State {
|
impl State {
|
||||||
|
@ -46,14 +46,14 @@ mod tests {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_match_message_call() {
|
fn test_match_message_call() {
|
||||||
let mut state = State{
|
let mut state = State {
|
||||||
quit: false,
|
quit: false,
|
||||||
position: Point{ x: 0, y: 0 },
|
position: Point { x: 0, y: 0 },
|
||||||
color: (0, 0, 0)
|
color: (0, 0, 0),
|
||||||
};
|
};
|
||||||
state.process(Message::ChangeColor((255, 0, 255)));
|
state.process(Message::ChangeColor((255, 0, 255)));
|
||||||
state.process(Message::Echo(String::from("hello world")));
|
state.process(Message::Echo(String::from("hello world")));
|
||||||
state.process(Message::Move(Point{ x: 10, y: 15 }));
|
state.process(Message::Move(Point { x: 10, y: 15 }));
|
||||||
state.process(Message::Quit);
|
state.process(Message::Quit);
|
||||||
|
|
||||||
assert_eq!(state.color, (255, 0, 255));
|
assert_eq!(state.color, (255, 0, 255));
|
||||||
|
@ -61,5 +61,4 @@ mod tests {
|
||||||
assert_eq!(state.position.y, 15);
|
assert_eq!(state.position.y, 15);
|
||||||
assert_eq!(state.quit, true);
|
assert_eq!(state.quit, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,4 +7,3 @@ fn main() {
|
||||||
let mut shopping_list: Vec<?> = Vec::new();
|
let mut shopping_list: Vec<?> = Vec::new();
|
||||||
shopping_list.push("milk");
|
shopping_list.push("milk");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
// I AM NOT DONE
|
// I AM NOT DONE
|
||||||
|
|
||||||
struct Wrapper {
|
struct Wrapper {
|
||||||
value: u32
|
value: u32,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Wrapper {
|
impl Wrapper {
|
||||||
|
|
|
@ -33,7 +33,10 @@ mod tests {
|
||||||
student_name: "Tom Wriggle".to_string(),
|
student_name: "Tom Wriggle".to_string(),
|
||||||
student_age: 12,
|
student_age: 12,
|
||||||
};
|
};
|
||||||
assert_eq!(report_card.print(), "Tom Wriggle (12) - achieved a grade of 2.1");
|
assert_eq!(
|
||||||
|
report_card.print(),
|
||||||
|
"Tom Wriggle (12) - achieved a grade of 2.1"
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
@ -44,6 +47,9 @@ mod tests {
|
||||||
student_name: "Gary Plotter".to_string(),
|
student_name: "Gary Plotter".to_string(),
|
||||||
student_age: 11,
|
student_age: 11,
|
||||||
};
|
};
|
||||||
assert_eq!(report_card.print(), "Gary Plotter (11) - achieved a grade of A+");
|
assert_eq!(
|
||||||
|
report_card.print(),
|
||||||
|
"Gary Plotter (11) - achieved a grade of A+"
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,10 +6,10 @@
|
||||||
macro_rules! my_macro {
|
macro_rules! my_macro {
|
||||||
() => {
|
() => {
|
||||||
println!("Check out my macro!");
|
println!("Check out my macro!");
|
||||||
}
|
};
|
||||||
($val:expr) => {
|
($val:expr) => {
|
||||||
println!("Look at this other macro: {}", $val);
|
println!("Look at this other macro: {}", $val);
|
||||||
}
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
|
|
|
@ -26,7 +26,10 @@ pub enum List {
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
println!("This is an empty cons list: {:?}", create_empty_list());
|
println!("This is an empty cons list: {:?}", create_empty_list());
|
||||||
println!("This is a non-empty cons list: {:?}", create_non_empty_list());
|
println!(
|
||||||
|
"This is a non-empty cons list: {:?}",
|
||||||
|
create_non_empty_list()
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn create_empty_list() -> List {
|
pub fn create_empty_list() -> List {
|
||||||
|
|
|
@ -17,7 +17,11 @@ impl Package {
|
||||||
if weight_in_grams <= 0 {
|
if weight_in_grams <= 0 {
|
||||||
// Something goes here...
|
// Something goes here...
|
||||||
} else {
|
} else {
|
||||||
return Package {sender_country, recipient_country, weight_in_grams};
|
return Package {
|
||||||
|
sender_country,
|
||||||
|
recipient_country,
|
||||||
|
weight_in_grams,
|
||||||
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -18,9 +18,6 @@ trait AppendBar {
|
||||||
|
|
||||||
//TODO: Add your code here
|
//TODO: Add your code here
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
|
|
Loading…
Reference in a new issue