3 ms·
- For those clicking the link and feeling unsure how to play around, there's a panel on top left where you can choose Examples as source, select a name (there's
by bilalhusain 12y ago
- For those clicking the link and feeling unsure how to play around, there's a panel on top left where you can choose Examples as source, select a name (there's only one at this time) and click load. Apologies for this silly advice (wasn't so obvious to me).
- For those attempting to run the example at Rust home page[1], use `pub fn main` instead of `fn main`
- You can also copy paste the following examples (switch on Colourise option avaiable in the top right panel)
// a. will the compiler multiply?
pub fn hours_to_milliseconds(h: int) -> int {
h * 60 * 60 * 1000
}
// b. optimizing index computations inside loop?
pub fn calculate_brightness(r: &[int, ..256], g: &[int, ..256], b: &[int, ..256]) -> f64 {
let mut sum = 0;
for i in range(0u, 128) {
sum += r[2*i] + r[2*i + 1];
sum += g[2*i] + g[2*i + 1];
sum += b[2*i] + b[2*i + 1];
}
(sum as f64) / 3.0
}
// c. macro expansion
pub fn main() {
println!("A {} has {} lives", "cat", 9);
}
[1] http://www.rust-lang.org/ http://www.rust-lang.org/