-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRuntimeploy8.rs
More file actions
74 lines (40 loc) · 1.56 KB
/
Copy pathRuntimeploy8.rs
File metadata and controls
74 lines (40 loc) · 1.56 KB
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
trait fmt {
fn display(&mut self); // exepctation from programmer will assign value to struct variable
// struct and method needs be implememted by coder
}
#[derive(Copy,Clone)]
struct variables{
datatypes:i8, // Box::new(variables{datatypes:8})
}
impl fmt for variables{
fn display(& mut self){ // stack memory
self.datatypes = 7; // value is assigned to strut variables object memory
println!("variables display");
}
}
#[derive(Copy,Clone)]
struct object{
structvariables:i8,
}
impl fmt for object{
fn display(& mut self){ // stack memory
self.structvariables = 9; // value is assigned to strut variables object memory
println!("objects display");
}
}
fn main(){
let mut obj:Vec<Box<dyn fmt>> = Vec::new();
// new function call return object of vec < box >
// obj stack points to heap
let programmer:variables = variables{datatypes:8} ; // stack
println!("{:p}",&programmer);
let freshers:object = object{structvariables:100} ;
let b = Box::new(programmer); // stack data copied to heap mmeory data copy boroowed
obj.push(Box::new(freshers)); // stack data copied to heap mmeory data copy boroowed
obj.push(Box::new(programmer));
println!("{}",programmer.datatypes);
// obj.push(Box::new(variables));
for mut i in obj{
i.display();
}
}