Skip to content

Instantly share code, notes, and snippets.

View lukeabela38's full-sized avatar

Luke Abela lukeabela38

View GitHub Profile
@lukeabela38
lukeabela38 / function_parameters.rs
Created August 28, 2022 12:11
Passing parameters into a Function.
fn main() {
function_with_parameters(7);
}
fn function_with_parameters(x: i32) {
println!("The value of x is: {x} ");
}
@lukeabela38
lukeabela38 / function_declaration.rs
Created August 28, 2022 12:06
Declaring a Function
fn main() {
hello();
}
fn hello() {
println!("Hello from my external function!");
}
@lukeabela38
lukeabela38 / arrays.rs
Created August 27, 2022 22:32
Operations with Arrays in Rust
fn main() {
// Declare an array known as 5 with five entries, each of which is a signed 32 integer
let a: [i32; 5] = [1, 2, 3, 4, 5];
// accessing the values of arrays
let first = a[0];
let second = a[1];
}
@lukeabela38
lukeabela38 / tuples.rs
Created August 27, 2022 10:30
Tuples in Rust
fn main () {
// This is a comment, with two forward slashes, we can leave comments
// in our code to explain to readers what is happening!
// declaring our tuple with a signed 32 bit integer, floating point 64 bit
// and an unsigned 8 bit integer
let tup: (i32, f64, u8) = (500, 6.4, 1);
// to read tuple data, we need to match its format
@lukeabela38
lukeabela38 / characters.rs
Created August 27, 2022 09:59
Declaring a character in Rust
fn main() {
let a: char = 'a';
let cat_in_love = '😻';
}
@lukeabela38
lukeabela38 / booleans.rs
Created August 27, 2022 09:56
Boolean Declaration in Rust
fn main() {
let t: bool = true;
let f: bool = false;
}
@lukeabela38
lukeabela38 / floating_point_numbers.rs
Created August 27, 2022 09:49
Declaring Floating Point Numbers in Rust
fn main() {
let x: f64 = 2.0;
let y: f32 = 1.0;
}
@lukeabela38
lukeabela38 / integers.rs
Created August 27, 2022 09:24
Settings Integers in Rust
fn main() {
let a: u8;
let b: u16;
let c: u32;
let d: u64;
let e: u128;
}
@lukeabela38
lukeabela38 / shadowing.rs
Last active August 27, 2022 08:55
Shadowing in Rust
fn main() {
let x = 5:
let x = x + 1;
}
@lukeabela38
lukeabela38 / constant.rs
Created August 27, 2022 08:45
Setting a constant in Rust
const THREE_HOURS_IN_SECONDS: u32 = 60 * 60 * 3;