Added chapter 7

This commit is contained in:
2020-06-11 16:55:56 -04:00
parent 3ecda72a85
commit 1e76dc4a17
2 changed files with 38 additions and 3 deletions

31
src/Expressions.rs Normal file
View File

@@ -0,0 +1,31 @@
pub fn main(){
/*
//variable binding
let x = 5;
//expression;
x;
x + 1;
15;
*/
let x = 5u32;
let y = {
let x_squared = x * x;
let x_cube = x_squared * x;
//This expression will be assigned to `y`
x_cube + x_squared + x
};
#[allow(unused_must_use)]
let z = {
//The semicolon suppresses this expression and `()` is assigned to `z`
2 * x;
};
println!("x is {:?}", x);
println!("y is {:?}", y);
println!("z is {:?}", z);
}

View File

@@ -7,6 +7,7 @@ mod CustomTypes;
mod VariableBindings; mod VariableBindings;
mod Types; mod Types;
mod Conversion; mod Conversion;
mod Expressions;
fn main(){ fn main(){
@@ -69,9 +70,12 @@ fn main(){
//6 Conversion //6 Conversion
//6.1 From and Into //6.1 From and Into
Conversion::FromAndInto::main(); //Conversion::FromAndInto::main();
//6.2 TryFrom and TryInto //6.2 TryFrom and TryInto
Conversion::TryFromAndTryInto::main(); //Conversion::TryFromAndTryInto::main();
//6.3 To and From Strings //6.3 To and From Strings
Conversion::ToAndFromStrings::main(); //Conversion::ToAndFromStrings::main();
//7 Expressions
Expressions::main();
} }