Skip to content

Discrepancy between example in 5.14 and solution #255

Open
@ericzundel

Description

@ericzundel

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!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions