Created
October 29, 2021 09:12
-
-
Save Shaun289/64e1e77f2d8b4e8c131ce3f93a21c785 to your computer and use it in GitHub Desktop.
Rust study : constants and static
This file contains hidden or 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
/* | |
The rust by example ko https://hanbum.gitbooks.io/rustbyexample/content/custom_types/constants.html | |
compiled on https://play.rust-lang.org/ | |
result: | |
running 1 test | |
test tests::const_test ... ok | |
test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s | |
*/ | |
// 글로벌은 모든 다른 범위 외부에서 선언된다. | |
static LANGUAGE: &'static str = "Rust"; | |
const THRESHOLD: i32 = 10; | |
fn is_big(n: i32) -> bool { | |
n > THRESHOLD | |
} | |
#[cfg(test)] | |
mod tests { | |
use super::*; | |
#[test] | |
fn const_test() { | |
let n = 16; | |
assert_eq!(LANGUAGE.eq("Rust"), true); | |
assert_eq!(THRESHOLD, 10); | |
assert_eq!(is_big(11), true); | |
assert_eq!(is_big(9), false); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment