Skip to content

Instantly share code, notes, and snippets.

@ebot
Created January 20, 2014 00:04
Show Gist options
  • Save ebot/8512768 to your computer and use it in GitHub Desktop.
Save ebot/8512768 to your computer and use it in GitHub Desktop.
My first basic rust program.
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