Created
January 20, 2014 00:04
-
-
Save ebot/8512768 to your computer and use it in GitHub Desktop.
My first basic rust program.
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
use std::io::buffered::BufferedReader; | |
use std::io; | |
fn get_name() -> ~str { | |
println!("What is your first name?"); | |
let mut reader = BufferedReader::new(io::stdin()); | |
let name = reader.read_line().unwrap_or(~"nothing"); | |
return name.trim().to_str(); | |
} | |
fn main() { | |
let name = get_name(); | |
let mut count = 0; | |
println!("\nHi {}! My name is rust.", name); | |
println!("I am going to count for you:"); | |
while count < 10 { | |
println!(" count is {}.", count); | |
count += 1; | |
} | |
} | |
#[test] | |
fn names_exist() { | |
let first_name = get_name(); | |
//first_name = get_name(); | |
if first_name == ~"" { | |
fail!("First Name not valid"); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment