mirror of
https://github.com/ahgamut/rust-ape-example.git
synced 2024-05-16 02:22:41 +00:00
30 lines
594 B
Rust
30 lines
594 B
Rust
// ./src/custom_types/constants.md
|
|
|
|
|
|
// Globals are declared outside all other scopes.
|
|
static LANGUAGE: &str = "Rust";
|
|
const THRESHOLD: i32 = 10;
|
|
|
|
fn is_big(n: i32) -> bool {
|
|
// Access constant in some function
|
|
n > THRESHOLD
|
|
}
|
|
|
|
fn part0() {
|
|
let n = 16;
|
|
|
|
// Access constant in the main thread
|
|
println!("This is {}", LANGUAGE);
|
|
println!("The threshold is {}", THRESHOLD);
|
|
println!("{} is {}", n, if is_big(n) { "big" } else { "small" });
|
|
|
|
// Error! Cannot modify a `const`.
|
|
// THRESHOLD = 5;
|
|
// FIXME ^ Comment out this line
|
|
}
|
|
|
|
pub fn main() {
|
|
part0();
|
|
}
|
|
|