Created
December 12, 2015 18:12
-
-
Save adaedra/6d4625876e1c4b829af3 to your computer and use it in GitHub Desktop.
This file contains 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::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() | |
} |
This file contains 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
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