Skip to content

Instantly share code, notes, and snippets.

@adaedra
Created December 12, 2015 18:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save adaedra/6d4625876e1c4b829af3 to your computer and use it in GitHub Desktop.
Save adaedra/6d4625876e1c4b829af3 to your computer and use it in GitHub Desktop.
use std::io::prelude::*;
use std::fs::File;
fn main() {
let word = get_word();
}
fn get_word() -> String {
let mut file = try!(File::open("wordlist"));
let mut contents = String::new();
file.read_to_string(&mut contents);
let words = contents.split('\n');
println!("There are {} words.", words.count());
words.next().unwrap().to_string()
}
adaedra ❯ cargo build
Compiling hangman v0.1.0 (file:///Users/adaedra/Work/rust/hangman)
<std macros>:5:8: 6:42 error: mismatched types:
expected `collections::string::String`,
found `core::result::Result<_, _>`
(expected struct `collections::string::String`,
found enum `core::result::Result`) [E0308]
<std macros>:5 return $ crate:: result:: Result:: Err (
<std macros>:6 $ crate:: convert:: From:: from ( err ) ) } } )
src/main.rs:9:20: 9:48 note: in this expansion of try! (defined in <std macros>)
<std macros>:5:8: 6:42 help: run `rustc --explain E0308` to see a detailed explanation
error: aborting due to previous error
Could not compile `hangman`.
To learn more, run the command again with --verbose.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment