Skip to content

Commit

Permalink
修正
Browse files Browse the repository at this point in the history
  • Loading branch information
sotanengel committed Jan 3, 2025
1 parent 334722e commit 5240058
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ fn do_something(flag: bool) -> Result<(), String> {
if flag {
Ok(())
} else {
String::from("Something went wrong")
"Something went wrong".to_string()
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ impl error::Error for AppError {
fn source(&self) -> Option<&(dyn error::Error + 'static)> {}
}

// 便利な変換を追加
// From<String> を実装して String からの変換を簡単に
impl From<io::Error> for AppError {
fn from(err: io::Error) -> Self {
AppError::NotFound(err)
Expand All @@ -53,7 +53,7 @@ fn do_something(input: &str) -> Result<(), AppError> {
"Input cannot be empty",
))?
} else if input == "404" {
Err::<(), AppError>(String::from("Requested resource not found").into())?
Err(AppError::from("Requested resource not found".to_string()))?
} else if input == "500" {
Err(io::Error::new(
io::ErrorKind::Other,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ fn do_something(flag: bool) -> Result<(), OriginalError> {
if flag {
Ok(())
} else {
Err(OriginalError(String::from("Something went wrong")))
Err(OriginalError::from("Something went wrong"))
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ impl error::Error for AppError {
}
}

// 便利な変換を追加
// From<String> を実装して String からの変換を簡単に
impl From<io::Error> for AppError {
fn from(err: io::Error) -> Self {
AppError::NotFound(err)
Expand All @@ -59,7 +59,7 @@ fn do_something(input: &str) -> Result<(), AppError> {
"Input cannot be empty",
))?
} else if input == "404" {
Err::<(), AppError>(String::from("Requested resource not found").into())?
Err(AppError::from("Requested resource not found".to_string()))?
} else if input == "500" {
Err(io::Error::new(
io::ErrorKind::Other,
Expand Down

0 comments on commit 5240058

Please sign in to comment.