-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathmain.rs
More file actions
34 lines (28 loc) · 1.05 KB
/
main.rs
File metadata and controls
34 lines (28 loc) · 1.05 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
fn main() {
let hello : String = String::from("Hello");
take(hello); // From take(): Hello WasmEdge!
// The following will fail since hello is already taken by take() and no longer available here
// println!("From main(): {}", hello);
let hello : String = String::from("Hello");
take(hello.clone()); // From take(): Hello WasmEdge!
println!("From main(): {}", hello); // From main(): Hello
let hello : String = String::from("Hello");
borrow(&hello); // From borrow(): Hello WasmEdge!
println!("From main(): {}", hello); // From main(): Hello
let mut hello : String = String::from("Hello");
borrow_mut(&mut hello); // From borrow_mut(): Hello WasmEdge!
println!("From main(): {}", hello); // From main(): Hello WasmEdge!
}
fn take (mut s: String) {
s.push_str(" WasmEdge!");
println!("From take(): {}", s);
}
fn borrow (s: &String) {
let mut buf = String::from(s);
buf.push_str(" WasmEdge!");
println!("From borrow(): {}", buf);
}
fn borrow_mut (s: &mut String) {
(*s).push_str(" WasmEdge!");
println!("From borrow_mut(): {}", s);
}