문제 // TODO: Add a new error variant to `TicketNewError` for when the status string is invalid.// When calling `source` on an error of that variant, it should return a `ParseStatusError` rather than `None`.#[derive(Debug, thiserror::Error)]pub enum TicketNewError { #[error("Title cannot be empty")] TitleCannotBeEmpty , #[error("Title cannot be longer than 50 bytes")] TitleTooLong, ..
풀이impl TryFrom for Status { type Error = (); fn try_from(value: String) -> Result { match value.to_lowercase().as_str() { "todo" => Ok(Status::ToDo), "done" => Ok(Status::Done), "inprogress" => Ok(Status::InProgress), _ => Err(()), } }}impl TryFrom for Status { type Error = (); fn try_from(value: &str) -> Result { ma..
문제// TODO: Implement the `Error` trait for `TicketNewError` using `thiserror`.// We've changed the enum variants to be more specific, thus removing the need for storing// a `String` field into each variant.// You'll also have to add `thiserror` as a dependency in the `Cargo.toml` file.풀이Cargo.toml의 [dependencies]에 ThisError="2.0.12"와 같이 추가하고, TicketNewError를 다음과 같이 수정한다.#[derive(thiserror:..
문제// 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) ->..