Code Blocks Test
Various tests for code blocks.
Simple
fn main(){ println!("Hello world!"); }
#![allow(unused)] fn main() { let guess: u32 = "42".parse().expect("Not a number!"); }
thread 'main' panicked at 'index out of bounds: the len is 5 but the index is 10', src/main.rs:19:19
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
With Hidden lines
fn main(){ println!("Hello world!"); }
#![allow(unused)] fn main() { println!("This has an implicit main."); }
fn main() { let s1 = String::from("hello"); let len = calculate_length(&s1); println!("The length of '{}' is {}.", s1, len); } fn calculate_length(s: &String) -> usize { // s is a reference to a String s.len() } // Here, s goes out of scope. But because it does not have ownership of what // it refers to, it is not dropped.
Options
println!("This should not have a playground play button shown.");
Editable
fn main(){ println!("Hello world!"); }
fn main() { let s1 = String::from("hello"); let len = calculate_length(&s1); println!("The length of '{}' is {}.", s1, len); } fn calculate_length(s: &String) -> usize { // s is a reference to a String s.len() } // Here, s goes out of scope. But because it does not have ownership of what // it refers to, it is not dropped.
let guess: u32 = "42".parse().expect("Not a number!");