rust-training
rust-training copied to clipboard
Error handling slides (3) shows `'static` lifetime and lifetimes have not been talked about
Where
Slide 3 of Error handling
What
Error handling slides (3) shows 'static lifetime and lifetimes have not been talked about yet in the course. It makes it harder to introduce this? Which is basically "ignore this". Maybe it is ok but still worth this ticket.
fn literals() -> Result<(), &'static str> { // <-- lifetime here
Err("oh no")
}
fn strings() -> Result<(), String> {
Err(String::from("oh no"))
}
fn enums() -> Result<(), Error> {
Err(Error::BadThing)
}
enum Error { BadThing, OtherThing }
Fix
Maybe use something that does not have a lifetime.
Yeah but at some point they're going to try and use string literals, and they need to know it's painful.
We covered this with an apology and said "don't worry about the details, this is unfortunately how you have to specify string literal in Rust as a type"
Dupe of #53?