$ cat 0101-guessing-game/src/
main.rsuse rand::Rng;
use std::cmp::Ordering;
fn main() {
let secret_number :u32 = rand::thread_rng().gen_range(1..=100);
let mut guess = String::new();
loop {
println!("Guess a number: ");
guess.clear();
std::io::stdin().read_line(&mut guess).expect("error reading line");
let guess : u32 = match guess.trim().parse() {
Ok(num) => num,
Err(err) => {
println!("{}", err);
continue
}
};
match secret_number.cmp(&guess) {
Ordering::Less => println!("Try lower."),
Ordering::Greater => println!("Try higher."),
Ordering::Equal => {
println!("That's it: {}", secret_number);
break;
}
}
}
}
$ cat 0102-output-julia/src/
main.rsuse std::io::Write;
fn main() {
let mut f : std::fs::File = std::fs::File::create("output.jl").expect("failed to create output.jl");
f.write_all(b"x = 4\nprintln(\"4 + 4 = $(x + 4)\")\n").expect("failed to write lines");
}
$ julia output.jl
4 + 4 = 8