mirror of
https://github.com/epasveer/seer.git
synced 2026-08-29 08:34:42 +08:00
Add a simple Rust test program.
This commit is contained in:
@@ -0,0 +1,3 @@
|
||||
hellorust
|
||||
*.seer
|
||||
core.*
|
||||
@@ -0,0 +1,10 @@
|
||||
.PHONY: all
|
||||
all: hellorust
|
||||
|
||||
hellorust: hellorust.rs
|
||||
rustc -g hellorust.rs
|
||||
|
||||
.PHONY: clean
|
||||
clean:
|
||||
rm -f hellorust
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
|
||||
Simple test program for Rust.
|
||||
|
||||
Use /usr/bin/rust-gdb as the gdb debugger. Set this in Seer's config dialog.
|
||||
|
||||
@@ -0,0 +1,37 @@
|
||||
// Unlike C/C++, there's no restriction on the order of function definitions
|
||||
fn main() {
|
||||
// We can use this function here, and define it somewhere later
|
||||
fizzbuzz_to(100);
|
||||
}
|
||||
|
||||
// Function that returns a boolean value
|
||||
fn is_divisible_by(lhs: u32, rhs: u32) -> bool {
|
||||
// Corner case, early return
|
||||
if rhs == 0 {
|
||||
return false;
|
||||
}
|
||||
|
||||
// This is an expression, the `return` keyword is not necessary here
|
||||
lhs % rhs == 0
|
||||
}
|
||||
|
||||
// Functions that "don't" return a value, actually return the unit type `()`
|
||||
fn fizzbuzz(n: u32) -> () {
|
||||
if is_divisible_by(n, 15) {
|
||||
println!("fizzbuzz");
|
||||
} else if is_divisible_by(n, 3) {
|
||||
println!("fizz");
|
||||
} else if is_divisible_by(n, 5) {
|
||||
println!("buzz");
|
||||
} else {
|
||||
println!("{}", n);
|
||||
}
|
||||
}
|
||||
|
||||
// When a function returns `()`, the return type can be omitted from the
|
||||
// signature
|
||||
fn fizzbuzz_to(n: u32) {
|
||||
for n in 1..=n {
|
||||
fizzbuzz(n);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user