Skip to content

Commit 04e82f8

Browse files
Update data_structures in Rust
1 parent 87d8297 commit 04e82f8

File tree

1 file changed

+42
-1
lines changed

1 file changed

+42
-1
lines changed

Languages/Rust/data_structures.rs

+42-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,48 @@
1-
use std::{collections::HashMap, hash::Hash};
1+
use std::collections::HashMap;
22

33
fn main() {
44
println!("Data structures: \n");
5+
println!("Integers");
6+
{
7+
let signed: i8 = -10;
8+
let unsigned: u8 = 10;
9+
10+
println!("Signed: {:?}\nUnsigned {:?}", signed, unsigned);
11+
}
12+
{
13+
let signed: i32 = -1000000000;
14+
let unsigned: u32 = 10;
15+
16+
let long_pos_number: u128 = 100000000000000000000000000000000000000;
17+
18+
println!("Signed: {:?}\nUnsigned {:?}\nLong positive number {:?}", signed, unsigned, long_pos_number);
19+
20+
let floating_point:f64 = 3.14;
21+
let floating_point_negative:f64 = -3.14845646546424212121214654654;
22+
let single_precision: f32 = 3.1454545465465465464;
23+
println!("Floating points: Positive: {floating_point} and Negative: {floating_point_negative}. Also there is f32, for single precision: {single_precision}");
24+
}
25+
26+
println!("Tuples");
27+
{
28+
let tuple: (u8, u8, &str) = (1,2,"3");
29+
println!("Cannot loop over tuples, but can access values with indexing, like tuple.0 is {0}", tuple.0);
30+
println!("But can destructure tuples");
31+
32+
let (x, _, _) = tuple;
33+
println!("x is {x}");
34+
35+
}
36+
37+
println!("Arrays"); {
38+
println!("Each element has to be of same type, size has to be fixed");
39+
40+
let arr: [i8; 3] = [1,2,3];
41+
42+
println!("Arrays have a lot of methods");
43+
println!("Can access by index, like arr[0] is {:?}", arr[0]);
44+
}
45+
546
println!("Vectors: \n");
647
{
748
let mut my_integer_array: Vec<u32> = Vec::new();

0 commit comments

Comments
 (0)