First I'm reading the book Learn Rust in a month of Lunches. So far so good but I wanted a little more explanation of enums.
So I watched the video here: https://youtu.be/-nFDSDE_2Nw?t=404 called ENUMS are at the HEART of Rust. At 6:44 in the author goes over using user text input. I followed along but keep running into a compile error:
typeerror: expected one of `)`, `,`, `@`, or `|`, found `:`
--> testenum-NOTWORKING.rs:9:26
|
9 | Book::Other(title: &String) => title.into(),
| ^ expected one of `)`, `,`, `@`, or `|`
error: aborting due to 1 previous error
So I simplified the code down to its bare bones trying to figure out what I messed up. Show here:
type or paste code enum Book {
// use a text input
Other(String),
}
fn display(book: &Book) -> String {
match book {
//Book::Other(title: &String()) => title.into(),
Book::Other(title: &String) => title.into(),
//Book::Other(title: &string) -> title.into(),
}
}
fn main() {
let yourFavBook: Book = Book::Other("Atomics and Locks".into());
println!("Your favorite book is: '{}'", display(&yourFavBook));
}here
But I can't seem to find anything online to help me figure out what I've done wrong. His code works and I cant see a typo in my code anywhere. Been on this on and off for over a day now and because I'm new to rust Im having a hard time figuring out how to solve. Can someone tell me whats wrong here and where I can find info about why its wrong? Maybe in the rustup docs? I would really appreciate any help. Thank you.