mirror of
https://bitbucket.org/Mattrixwv/rusttutorials.git
synced 2025-12-06 18:43:57 -05:00
Added chapter 7
This commit is contained in:
31
src/Expressions.rs
Normal file
31
src/Expressions.rs
Normal 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);
|
||||||
|
}
|
||||||
10
src/main.rs
10
src/main.rs
@@ -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();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user