Skip to content

Commit 27a401c

Browse files
committed
rust course examples
0 parents  commit 27a401c

File tree

4 files changed

+84
-0
lines changed

4 files changed

+84
-0
lines changed

README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# Rust Examples
2+
Bart Massey 2021
3+
4+
Various small examples from my Rust course. Previously a lot
5+
of these were on the playground, but I prefer to have them
6+
in a controlled repository now.
7+
8+
* `datatypes`: examples of various datatype thingies

datatypes/Cargo.lock

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

datatypes/Cargo.toml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
[package]
2+
name = "datatypes"
3+
version = "0.1.0"
4+
authors = ["Bart Massey <[email protected]>"]
5+
edition = "2018"

datatypes/src/main.rs

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
fn _even1() {
2+
let x = 5;
3+
if x % 2 == 1 {
4+
println!("even {}", x + 1);
5+
} else {
6+
let q = '?';
7+
println!("{}", q);
8+
}
9+
}
10+
11+
fn _even2() {
12+
let x = 5;
13+
let x =
14+
if x % 2 == 1 {
15+
x + 1
16+
} else {
17+
x
18+
};
19+
println!("even {}", x);
20+
}
21+
22+
fn _evens() {
23+
for i in (0..10).step_by(2) {
24+
println!("{}", i);
25+
}
26+
}
27+
28+
fn _one() {
29+
let x = { 1 };
30+
println!("{}", x);
31+
}
32+
33+
fn _matchy(x: u8) {
34+
let y = match x {
35+
0 => 5,
36+
1 => panic!("oops"),
37+
p => p + 1,
38+
};
39+
println!("{}", y);
40+
}
41+
42+
fn _diverge() -> ! {
43+
println!("bye");
44+
std::process::exit(0);
45+
}
46+
47+
fn _fn_values() {
48+
fn returns_unit() {
49+
println!("in function");
50+
}
51+
let f = returns_unit;
52+
let x = f();
53+
println!("{:?}", x);
54+
}
55+
56+
fn copy() {
57+
// let x = "string".to_string();
58+
let x = true;
59+
let y = x;
60+
let z = x;
61+
println!("{} {} {}", x, y, z);
62+
}
63+
64+
fn main() {
65+
copy();
66+
}

0 commit comments

Comments
 (0)