Revert "did more"

This reverts commit 77290b0c56c2b50809ad57e549d233c12c2d9033.
This commit is contained in:
Stanislav Pankrashin 2022-06-23 17:06:21 +12:00
parent 3f7ddeb5c1
commit e0a2cbf8cd
9 changed files with 36 additions and 26 deletions

View File

@ -2,6 +2,8 @@
// Fill in the rest of the line that has code missing!
// No hints, there's no tricks, just get used to typing these :)
// I AM NOT DONE
fn main() {
// Booleans (`bool`)
@ -10,7 +12,7 @@ fn main() {
println!("Good morning!");
}
let is_evening: bool = true;// Finish the rest of this line like the example! Or make it be false!
let // Finish the rest of this line like the example! Or make it be false!
if is_evening {
println!("Good evening!");
}

View File

@ -2,6 +2,8 @@
// Fill in the rest of the line that has code missing!
// No hints, there's no tricks, just get used to typing these :)
// I AM NOT DONE
fn main() {
// Characters (`char`)
@ -14,7 +16,7 @@ fn main() {
println!("Neither alphabetic nor numeric!");
}
let your_character: char = '1';// Finish this line like the example! What's your favorite character?
let // Finish this line like the example! What's your favorite character?
// Try a letter, try a number, try a special character, try a character
// from a different language than your own, try an emoji!
if your_character.is_alphabetic() {

View File

@ -2,8 +2,10 @@
// Create an array with at least 100 elements in it where the ??? is.
// Execute `rustlings hint primitive_types3` for hints!
// I AM NOT DONE
fn main() {
let a = [0; 100];
let a = ???
if a.len() >= 100 {
println!("Wow, that's a big array!");

View File

@ -2,11 +2,13 @@
// Get a slice out of Array a where the ??? is so that the test passes.
// Execute `rustlings hint primitive_types4` for hints!!
// I AM NOT DONE
#[test]
fn slice_out_of_array() {
let a = [1, 2, 3, 4, 5];
let nice_slice = &a[1..4];
let nice_slice = ???
assert_eq!([2, 3, 4], nice_slice)
}

View File

@ -2,9 +2,11 @@
// Destructure the `cat` tuple so that the println will work.
// Execute `rustlings hint primitive_types5` for hints!
// I AM NOT DONE
fn main() {
let cat = ("Furry McFurson", 3.5);
let (name, age)/* your pattern here */ = cat;
let /* your pattern here */ = cat;
println!("{} is {} years old.", name, age);
}

View File

@ -1,13 +1,15 @@
// primitive_types6.rs
// Use a tuple index to access the second element of `numbers`.
// You can put the expression for the second element where ??? is so that the test passes.
// Execute `rustlings hint primitive_types6` for hints!q
// Execute `rustlings hint primitive_types6` for hints!
// I AM NOT DONE
#[test]
fn indexing_tuple() {
let numbers = (1, 2, 3);
// Replace below ??? with the tuple indexing syntax.
let second = numbers.1;
let second = ???;
assert_eq!(2, second,
"This is not the 2nd number in the tuple!")

View File

@ -1,12 +1,13 @@
// structs1.rs
// Address all the TODOs to make the tests pass!
// I AM NOT DONE
struct ColorClassicStruct {
name: String,
hex: String,
// TODO: Something goes here
}
struct ColorTupleStruct(String, String);
struct ColorTupleStruct(/* TODO: Something goes here */);
#[derive(Debug)]
struct UnitStruct;
@ -18,10 +19,7 @@ mod tests {
#[test]
fn classic_c_structs() {
// TODO: Instantiate a classic c struct!
let green = ColorClassicStruct {
name: "green".to_string(),
hex: "#00FF00".to_string()
};
// let green =
assert_eq!(green.name, "green");
assert_eq!(green.hex, "#00FF00");
@ -30,7 +28,7 @@ mod tests {
#[test]
fn tuple_structs() {
// TODO: Instantiate a tuple struct!
let green = ColorTupleStruct("green".to_string(), "#00FF00".to_string());
// let green =
assert_eq!(green.0, "green");
assert_eq!(green.1, "#00FF00");
@ -39,7 +37,7 @@ mod tests {
#[test]
fn unit_structs() {
// TODO: Instantiate a unit struct!
let unit_struct = UnitStruct;
// let unit_struct =
let message = format!("{:?}s are fun!", unit_struct);
assert_eq!(message, "UnitStructs are fun!");

View File

@ -1,6 +1,8 @@
// structs2.rs
// Address all the TODOs to make the tests pass!
// I AM NOT DONE
#[derive(Debug)]
struct Order {
name: String,
@ -32,11 +34,7 @@ mod tests {
fn your_order() {
let order_template = create_order_template();
// TODO: Create your own order using the update syntax and template above!
let your_order = Order {
name: String::from("Hacker in Rust"),
count: 1,
..order_template
};
// let your_order =
assert_eq!(your_order.name, "Hacker in Rust");
assert_eq!(your_order.year, order_template.year);
assert_eq!(your_order.made_by_phone, order_template.made_by_phone);

View File

@ -4,6 +4,8 @@
// Make the code compile and the tests pass!
// If you have issues execute `rustlings hint structs3`
// I AM NOT DONE
#[derive(Debug)]
struct Package {
sender_country: String,
@ -14,7 +16,7 @@ struct Package {
impl Package {
fn new(sender_country: String, recipient_country: String, weight_in_grams: i32) -> Package {
if weight_in_grams <= 0 {
panic!("Oh noes")
// panic statement goes here...
} else {
Package {
sender_country,
@ -24,12 +26,12 @@ impl Package {
}
}
fn is_international(&self) -> bool {
self.sender_country != self.recipient_country
fn is_international(&self) -> ??? {
// Something goes here...
}
fn get_fees(&self, cents_per_gram: i32) -> i32 {
cents_per_gram * self.weight_in_grams
fn get_fees(&self, cents_per_gram: i32) -> ??? {
// Something goes here...
}
}