Skip to content

Instantly share code, notes, and snippets.

View georgematos's full-sized avatar
🎯
Focusing

George Matos georgematos

🎯
Focusing
View GitHub Profile
@georgematos
georgematos / derreferences.rs
Created May 17, 2024 00:55
Rust - reference and derreference
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;
@georgematos
georgematos / loop_vs_while_for.rs
Last active May 3, 2024 13:00
Rust - loop vs while vs for
fn main() {
let mut count = 3;
loop {
if count > 0 {
println!("{count}!");
count -= 1;
} else {
@georgematos
georgematos / loop.rs
Created May 3, 2024 12:18
Rust - loop and inner loop
// 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 };
@georgematos
georgematos / destructure.rs
Last active May 2, 2024 14:24
Rust - destructuring (tuple exemple) sample
// destructure
fn main() {
let tuple: (i32, f64, String) = (500, 38.8, "Rust".to_string());
let (a, b, c) = tuple;
println!("content: {a}, {b}, {c}")
}
@georgematos
georgematos / shadowing.rs
Last active May 2, 2024 14:25
Rust - Shadowing sample
// 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}");