-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #8 from cs-dust/integration
Integration
- Loading branch information
Showing
25 changed files
with
949 additions
and
201 deletions.
There are no files selected for viewing
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
fn main() { | ||
let x = 5; | ||
|
||
let y = { | ||
let x_squared = x * x; | ||
let x_cube = x_squared * x; | ||
|
||
// This expression will be assigned to `y` | ||
x_cube + x_squared + x | ||
}; | ||
|
||
let z = { | ||
// The semicolon suppresses this expression and `()` is assigned to `z` | ||
2 * x; | ||
}; | ||
|
||
println("x is {:?}", x); | ||
println("y is {:?}", y); | ||
println("z is {:?}", z); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,13 @@ | ||
fn main() { | ||
// bool | ||
let a = true; | ||
println("a is ", a); | ||
let b = false; | ||
let bool_expr = a && b; | ||
println("b is ", b); | ||
|
||
println("a && b gives ", bool_expr); | ||
let bool_and = a && b; | ||
println("a && b gives ", bool_and); | ||
|
||
let bool_or = a || b; | ||
println("a || b gives ", bool_or); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
fn main() { | ||
// A counter variable | ||
let mut n = 1; | ||
|
||
// Loop while `n` is less than 101 | ||
while n < 10 { | ||
if n == 5 || n == 7 { | ||
println("fizz"); | ||
} else { | ||
println("buzz"); | ||
} | ||
// Increment counter | ||
n = n + 1; | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
fn main() { | ||
fn nested_function(x: i64, y: i64) -> i64 { | ||
x + y | ||
} | ||
println("nested function adds 5 and 10 as", nested_function(five(), ten())); | ||
println("normal function adds 5 and 10 as", add(five(), ten())); | ||
} | ||
|
||
fn five() -> i64 { | ||
5 | ||
} | ||
|
||
fn ten() -> i64 { | ||
10 | ||
} | ||
|
||
fn add(x: i64, y: i64) -> i64 { | ||
x + y | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,17 @@ | ||
fn main() { | ||
// addition | ||
let sum = 5 + 10; | ||
let x = 5; | ||
let y = 1; | ||
println("x is ", x); | ||
println("y is ", y); | ||
|
||
let multiply = 8 * 9; | ||
let sum = x + y; | ||
println("sum = x + y is ", sum); | ||
|
||
let divide = 10/4; | ||
let multiply = x * 9; | ||
println("x * 9 is ", multiply); | ||
|
||
let subtract = 20 - 10; | ||
let divide = 10/x; | ||
println("10 / x is ", divide); | ||
|
||
println("x - y is ", x - y); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
fn main() { | ||
let number = 1; | ||
makes_copy(number); | ||
println("integer number after function call ", number); | ||
|
||
let x = "hello"; | ||
takes_ownership(x); | ||
println("string x after function call: ", x); | ||
} | ||
|
||
fn takes_ownership(s: String) { | ||
println("Taken ownership of", s); | ||
} | ||
|
||
fn makes_copy(i: i64) { | ||
println("Made a copy of ", i); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
fn main() { | ||
let a = 2093; | ||
let b = true; | ||
let c = "help i am owned by c :("; | ||
let d = (); // Unassigned | ||
println("a is an integer: ", a); | ||
println("b is a boolean: ", b); | ||
println("c is an owned string: ", c); | ||
println("d is unitliteral: ", d); | ||
println("this is an immutable string"); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
fn main() { | ||
let x = 1; | ||
println("x is ", x); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
fn main() { | ||
1 + 2; | ||
println("1 + 2 gives", 1 + 2); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
fn main() { | ||
!true; | ||
println("!true gives: ", !true); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
fn main() { | ||
let a = "hello"; | ||
let b = " world"; | ||
let c = a + b; | ||
println("a should have moved: ", a); | ||
println("b should remain since it was borrowed", b); | ||
println("c is the new concatenated string", c); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
fn main() { | ||
let a = "hello"; | ||
let c = a + " world"; | ||
println("a should have moved: ", a); | ||
println("c is the new concatenated string", c); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
fn main() { | ||
let str = "bing chillin"; | ||
println(str); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
fn main() { | ||
let a = "hello"; | ||
let b = a; | ||
println(a); | ||
println(b); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
fn main() { | ||
let a = "sad"; | ||
let b = " lol"; | ||
a = b; | ||
println("a should have a changed value", a); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.