rust-training icon indicating copy to clipboard operation
rust-training copied to clipboard

Error handling slides (3) shows `'static` lifetime and lifetimes have not been talked about

Open amanjeev opened this issue 2 years ago • 2 comments

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.

amanjeev avatar Jun 08 '23 13:06 amanjeev

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"

jonathanpallant avatar Jun 08 '23 14:06 jonathanpallant

Dupe of #53?

jonathanpallant avatar Jun 08 '23 15:06 jonathanpallant