ferrous-systems / rust-training

Learning materials for the Rust Training courses by Ferrous Systems
127 stars 16 forks source link

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

Open amanjeev opened 1 year ago

amanjeev commented 1 year ago

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.

jonathanpallant commented 1 year ago

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 commented 1 year ago

Dupe of #53?