문제// TODO: Add `anyhow` as a dependency of this project.// Don't touch this import!// When you import a type (`Error`) from a dependency, the import path must start// with the crate name (`anyhow`, in this case).use anyhow::Error;풀이[package]name = "deps"version = "0.1.0"edition = "2021"[dependencies]anyhow = "1.0.97" Cargo.toml에 dependencies를 추가한다.
문제// This is a `main.rs` file, therefore `cargo` interprets this as the root of a binary target.// TODO: fix this broken import. Create a new library target in the `src` directory.// The library target should expose a public function named `hello_world` that takes no arguments// and returns nothing.use packages::hello_world;// This is the entrypoint of the binary.fn main() { hello_world()..
문제 & 풀이// TODO: TicketNewError 열거형에 `Debug`, `Display`, `Error` 트레이트를 구현하세요.// `Display`를 구현할 때, `write!` 매크로를 사용하고 싶을지도 모릅니다.// `std::fmt` 모듈의 문서는 좋은 예시가 될 것입니다.// https://doc.rust-lang.org/std/fmt/index.html#write#[derive(Debug)]enum TicketNewError { TitleError(String), DescriptionError(String),}impl std::fmt::Display for TicketNewError { fn fmt(&self, f: &mut std::fmt::Formatter) ->..
문제// TODO: title error와 description error에 대응하는 두 개의 배리언트를 사용합니다.// 각각의 배리언트는 무엇이 잘못되었는지 설명하는 문자열을 포함해야 합니다.// `Ticket::new`의 구현 또한 업데이트해야 할 것입니다.enum TicketNewError { }// TODO: `easy_ticket`은 title이 잘못되면 panic을 일으켜야 하고,// `TicketNewError` 열거형에서 관련된 배리언트에 저장된 에러 메시지를 사용합니다.// description이 잘못되면 "Description not provided"라는 기본 description을 사용합니다.fn easy_ticket(title: String, description: String, s..
문제// TODO: `easy_ticket`은 title이 유효하지 않을 때 panic이 발생해야 합니다.// description이 유효하지 않다면 "Description not provided"라는 기본 description을 사용합니다.fn easy_ticket(title: String, description: String, status: Status) -> Ticket { todo!()}#[derive(Debug, PartialEq, Clone)]struct Ticket { title: String, description: String, status: Status,}#[derive(Debug, PartialEq, Clone)]enum Status { ToDo, In..
문제// TODO: `Ticket::new`를 panic 대신 `Result`를 리턴하도록 변환하세요.// 에러 타입으로는 `String`을 사용합니다.#[derive(Debug, PartialEq)]struct Ticket { title: String, description: String, status: Status,}#[derive(Debug, PartialEq)]enum Status { ToDo, InProgress { assigned_to: String }, Done,}impl Ticket { pub fn new(title: String, description: String, status: Status) -> Ticket { if title.is_..