oh just cargo fmt it all
This commit is contained in:
@@ -30,7 +30,7 @@ pub fn run() {
|
||||
|
||||
// You can also use if in a let statements, as such
|
||||
let condition = true;
|
||||
let number = if condition {5} else {6};
|
||||
let number = if condition { 5 } else { 6 };
|
||||
println!("The value of the conditional number is {number}");
|
||||
|
||||
// repitition with loops
|
||||
@@ -55,7 +55,7 @@ pub fn run() {
|
||||
// guess. Let's go slowly through this
|
||||
|
||||
let mut count = 0;
|
||||
'counting_up: loop{
|
||||
'counting_up: loop {
|
||||
println!("count = {count}");
|
||||
let mut remaining = 10;
|
||||
|
||||
@@ -99,5 +99,4 @@ pub fn run() {
|
||||
println!("{number_for}");
|
||||
}
|
||||
println!("for loop LIFTOFF!!!");
|
||||
|
||||
}
|
||||
|
||||
@@ -7,7 +7,6 @@ pub fn run() {
|
||||
|
||||
println!("delcared floats: \nvar x: {x} \nvar y: {y}");
|
||||
|
||||
|
||||
println!("\n=== 2.2 numeric ops ===\n");
|
||||
// addition
|
||||
let sum = 5 + 10;
|
||||
@@ -24,9 +23,9 @@ pub fn run() {
|
||||
|
||||
// remainder
|
||||
let remainder = 43 % 5;
|
||||
println!("5 + 10: {sum}\n95.5 - 4.3: {difference}\n4 * 30: {product}\n56.7 divided by 32.2: {quotient}\ntruncated -5 / 3: {truncated}\n43 % 5: {remainder}\n");
|
||||
|
||||
|
||||
println!(
|
||||
"5 + 10: {sum}\n95.5 - 4.3: {difference}\n4 * 30: {product}\n56.7 divided by 32.2: {quotient}\ntruncated -5 / 3: {truncated}\n43 % 5: {remainder}\n"
|
||||
);
|
||||
|
||||
println!("\n=== 2.2 compound types ===\n");
|
||||
println!("\n=== tuples ===\n");
|
||||
@@ -55,15 +54,30 @@ pub fn run() {
|
||||
let index_one = tup2.1;
|
||||
let index_two = tup2.2;
|
||||
|
||||
println!("here are the tuple decustructed indexed values method: index zero: {}, index one: {}, index two: {}", index_zero, index_one, index_two);
|
||||
println!(
|
||||
"here are the tuple decustructed indexed values method: index zero: {}, index one: {}, index two: {}",
|
||||
index_zero, index_one, index_two
|
||||
);
|
||||
println!("\n=== arrays ===\n");
|
||||
// Arrays can only contain one type. Arrays in rust have a fixed length.
|
||||
// syntax is as such: let a = [1,2,3,4,5];
|
||||
// arrays live on the stack. only use if you always know the number of items in the array.
|
||||
// Else, chances are you want to use vectors from the std lib. Vectors live in the heap. This is covered later in the book.
|
||||
|
||||
let months = ["January", "February", "March", "April", "May", "June", "July",
|
||||
"August", "September", "October", "November", "December"];
|
||||
let months = [
|
||||
"January",
|
||||
"February",
|
||||
"March",
|
||||
"April",
|
||||
"May",
|
||||
"June",
|
||||
"July",
|
||||
"August",
|
||||
"September",
|
||||
"October",
|
||||
"November",
|
||||
"December",
|
||||
];
|
||||
|
||||
// you can initialize the array with type and length as such:
|
||||
// let a: [i32;5] = [1,2,3,4,5];
|
||||
@@ -73,9 +87,9 @@ pub fn run() {
|
||||
let third_month = months[2];
|
||||
let fifth_month = months[4];
|
||||
|
||||
println!("now we access the month array by index. The third month is {third_month}. The fifth month is {fifth_month}");
|
||||
println!(
|
||||
"now we access the month array by index. The third month is {third_month}. The fifth month is {fifth_month}"
|
||||
);
|
||||
|
||||
// Note, the compiler will complain if you try to access a value that is outside the array
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -29,8 +29,8 @@ fn print_labeled_measurement(value: u32, unit_label: char) {
|
||||
}
|
||||
|
||||
// Statements and expressions
|
||||
// Okay, as I understand it, statements are the majority of code we have written so far.
|
||||
// statements end with semi colon (;), and do not return anything.
|
||||
// Okay, as I understand it, statements are the majority of code we have written so far.
|
||||
// statements end with semi colon (;), and do not return anything.
|
||||
// Expressions do NOT end with (;), but do return something. Look at these examples:
|
||||
|
||||
fn five() -> u32 {
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
mod variables;
|
||||
mod control_flow;
|
||||
mod data_types;
|
||||
mod functions;
|
||||
mod control_flow;
|
||||
mod variables;
|
||||
|
||||
fn main() {
|
||||
variables::run();
|
||||
|
||||
Reference in New Issue
Block a user