This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fn main() { | |
let pointer_1 = String::from("Hello"); | |
let pointer_2 = String::from("World"); | |
let pointer_3 = "a literal string"; | |
// cria o ponteiro pointer_4 apontando para 1 na heap | |
let pointer_4: Box<i32> = Box::new(1); | |
// cria uma referência do tipo Box<i32> para o pointer_4 | |
let reference_1: &Box<i32> = &pointer_4; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fn main() { | |
let mut count = 3; | |
loop { | |
if count > 0 { | |
println!("{count}!"); | |
count -= 1; | |
} else { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// loop and inner loop | |
fn main() { | |
// this little piece of code is simply printing a counting 0 to 9 | |
// whit a regressive counting 9 to 1 between each number | |
let mut count = 0; | |
'root_loop:loop { | |
println!("Count: {count}"); | |
count += 1; | |
if count == 10 { break 'root_loop }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// destructure | |
fn main() { | |
let tuple: (i32, f64, String) = (500, 38.8, "Rust".to_string()); | |
let (a, b, c) = tuple; | |
println!("content: {a}, {b}, {c}") | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// shadowing sample | |
fn main() { | |
let x = 5; | |
// shadowing x variable | |
let x = x + 1; // at this point the x was overrided with a new value | |
println!("The value of x: {x}"); | |
{ | |
// current shadowing only lives within that scope | |
let x = x * 2; | |
println!("The value of x: {x}"); |