-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvector.rs
52 lines (22 loc) · 777 Bytes
/
vector.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#![allow(dead_code)]
fn main() {
//explicit vector defination
let mut i32_vec = Vec::<i32>::new();
i32_vec.push(1);
i32_vec.push(2);
i32_vec.push(3);
//implicit vector defination
let mut float_vec = Vec::new();
float_vec.push([1.0,2.0,3.0]);
//use of macros vector defination
let string_vec = vec![String::from("hello"),String::from("world"),String::from("!")];
for word in string_vec.iter(){
println!("{:#?}",word);
}
//using from
let vec = vec!([1,2,3,String::from("hello")]);
println!("i32 vector : {:?}" ,i32_vec);
println!("string vector : {:?}" ,string_vec);
println!("float vector : {:#?}",float_vec);
println!("mixed vector : {}",vec);
}