Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Discrepancy between example in 5.14 and solution #255

Open
ericzundel opened this issue Feb 1, 2025 · 0 comments
Open

Discrepancy between example in 5.14 and solution #255

ericzundel opened this issue Feb 1, 2025 · 0 comments

Comments

@ericzundel
Copy link

This isn't really a bug, but both my partner and I learning Rust felt that 5.14 was a beast! I had to cheat and look at the solution. My partner used an LLM and got an answer very much unlike what we had learned to date.

I was confused by something I saw in the solution brand. The example for how to use #from in 5.14 reads as follows:

#[derive(Error, Debug)]
pub enum MyError {
    #[error("Failed to connect to the database")]
    DatabaseError {
        #[from]
        inner: std::io::Error
    }
}

Note that the syntax in the example uses the structure form of associating data with the enum
But in the solution, Database Error uses parens

[derive(Debug, thiserror::Error)]
pub enum TicketNewError {
    ...
    #[error("{0}")]
    InvalidStatus(#[from] ParseStatusError),
}

Tuples or tuple like syntax is covered in the Nullability lesson 5.5 , but never used in an exercise before this one. Tricky!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant