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
75
76
77
78
79
80
81
82
| | #+Title: a collection of examples for ob-rust tests
#+OPTIONS: ^:nil
#+name: test-simple
#+BEGIN_SRC rust :results silent
fn main() {
let answer = 42;
println!("{}", answer);
}
#+END_SRC
#+name: test-main-wrapper
#+BEGIN_SRC rust :results silent
let answer = 42;
println!("{}", answer);
#+END_SRC
#+name: test-var-integer
#+BEGIN_SRC rust :var answer=42 :results silent
println!("{}", answer);
#+END_SRC
#+name: test-var-float
#+BEGIN_SRC rust :var pi=3.14 :results silent
println!("{}", pi);
#+END_SRC
#+name: test-var-char
#+BEGIN_SRC rust :var answer='x' :results silent
println!("{}", answer);
#+END_SRC
#+name: test-var-string
#+BEGIN_SRC rust :var answer="GOAT" :results silent
println!("{}", answer);
#+END_SRC
#+name: test-var-bool-true
#+BEGIN_SRC rust :var test='true :results silent
if test {
println!("42");
}
#+END_SRC
#+name: test-var-bool-false
#+BEGIN_SRC rust :var test="false" :results silent
if !test {
println!("42");
}
#+END_SRC
#+name: test-var-mutable
#+BEGIN_SRC rust :var mut_answer=41 :results silent
answer = 42;
println!("{}", answer);
#+END_SRC
#+name: test-var-given-type
#+BEGIN_SRC rust :var answer:i32=40 :results silent
let additional_answer: i32 = 2;
println!("{}", answer + additional_answer);
#+END_SRC
#+name: test-var-mutable-and-given-type
#+BEGIN_SRC rust :var mut_answer:i32=40 :results silent
let additional_answer: i32 = 2;
answer = answer + additional_answer;
println!("{}", answer);
#+END_SRC
#+name: test-var-no-main-wrapper
#+BEGIN_SRC rust :var answer=42 :results silent
fn main() {
println!("{}", answer);
}
#+END_SRC
#+name: test-uses-and-command-line-arguments
#+BEGIN_SRC rust :use std::env :cmdline 1 2 bonjour :results silent
let args: Vec<String> = env::args().collect();
println!("{}, {}, {}", args[1], args[2], args[3]);
#+END_SRC
|