so heres my small application:
use std::io;
struct Character {
name: String,
}
fn build_character(name: String) -> Character {
Character {
name: name
}
}
fn lauch_adventure(adventure: String) {
match adventure {
"a" => launch_dark_harvest(),
_ => println!("Invalid input.")
}
}
fn launch_dark_harvest() {
println!("Welcome to Dark Harvest!");
}
fn main() {
println!("Whats your name?");
let mut name = String::new();
io::stdin()
.read_line(&mut name)
.expect("What?");
let character = build_character(name);
println!("Welcome {}", character.name);
println!("====[ Adventures ]====");
println!("a) Dark Heart");
println!("\nPlease Choose by typing the letter beside the name: ");
let mut choice = String::new();
io::stdin()
.read_line(&mut choice)
.expect("What?");
lauch_adventure(choice);
}
the issue is in the launch_adventure
method, where it fails to compile because of:
error[E0308]: mismatched types
--> src/main.rs:15:9
|
14 | match adventure {
| --------- this expression has type `std::string::String`
15 | "a" => launch_dark_harvest(),
| ^^^ expected struct `std::string::String`, found `&str`
I have tried everything on the internet to no avail, what am I missing? How do I match a user input string to given acceptable params?