Skip to content

Instantly share code, notes, and snippets.

@romyilano
Created July 14, 2024 22:47
Show Gist options
  • Save romyilano/5be835edf5c6bbf6c6fc089321a1aa0e to your computer and use it in GitHub Desktop.
Save romyilano/5be835edf5c6bbf6c6fc089321a1aa0e to your computer and use it in GitHub Desktop.
rust fun
fn main() {
println!("Hello, world!");
// fixed sized array
let arr1 : [i32; 4] = [3, 23, 4, 2];
println!("first element of array {}", arr1[0]);
println!("the array is {} long", arr1.len());
let xs: [i64; 2] = [1, 3];
// Arrays are stack allocated.
println!("Array occupies {} bytes", std::mem::size_of_val(&xs));
let large_array: [i128; 2000] = [0; 2000];
println!("the large array is {} bytes", std::mem::size_of_val(&large_array));
println!("the count of large array is {} items", large_array.len());
let mut baby_vector: Vec<i32> = vec![3,2,5];
println!("baby vector is {} items", baby_vector.len());
baby_vector.push(32);
let mut new_vector: Vec<i32> = Vec::new();
new_vector.push(252);
new_vector.push(338);
println!("New vector mutable array of type integer 32 bit is now {:?}", &new_vector);
let names: [&str; 3] = ["Fatima", "Tal", "Mayumi"];
println!("names {:?}", &names);
// can you put string immutable string slices in the heap?
let mut vector_names: Vec<&str> = Vec::new();
vector_names.push("Fatima");
println!("the vector names are {:?}", vector_names);
vector_names.push("Tal");
for element in &names {
vector_names.push(*element);
}
println!("The vectors names are {:?}", vector_names);
println!("The arraynames are {:?}!", names);
let mut names: Vec<String> = Vec::new();
names.push("Fatima".to_string());
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment