Skip to content

(05) ticket_v2 - (07) unwrap has nothing (necessarily) to do with unwrapping #285

Open
@shblack

Description

@shblack

This one seems completely disconnected from the parallel text. Unwrapping is not necessarily involved, at all, in solving the problem. It's not even particularly suggested by the way the problem is presented.

// TODO: `easy_ticket` should panic when the title is invalid.
//   When the description is invalid, instead, it should use a default description:
//   "Description not provided".
fn easy_ticket(title: String, description: String, status: Status) -> Ticket {
    // Validate title and panic if invalid
    if title.is_empty() {
        panic!("Title cannot be empty");
    }
    if title.len() > 50 {
        panic!("Title cannot be longer than 50 bytes");
    }

    // Use default description if description is invalid
    let final_description = if description.is_empty() || description.len() > 500 {
        "Description not provided".to_string()
    } else {
        description
    };

    Ticket {
        title,
        description: final_description,
        status,
    }
}

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