Skip to content

Commit ed7f5b0

Browse files
committed
use thiserror to format error
1 parent 0ee9cf1 commit ed7f5b0

4 files changed

Lines changed: 65 additions & 1 deletion

File tree

topics/tic-tac-toe/Cargo.lock

Lines changed: 58 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

topics/tic-tac-toe/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@ version = "0.1.0"
44
edition = "2024"
55

66
[dependencies]
7+
thiserror = "2.0.17"

topics/tic-tac-toe/src/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ fn main() {
1616
println!("It's a tie!");
1717
}
1818
Err(_e) => {
19-
eprintln!("An error occurred");
19+
eprintln!("An error occurred: {:?}", _e);
2020
}
2121
}
2222
}

topics/tic-tac-toe/src/types.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
use thiserror::Error;
2+
13
pub type Position = u8;
24

35
pub type Grid = [Option<PlayerID>; 9];
@@ -9,7 +11,10 @@ pub enum PlayerID {
911
}
1012

1113
pub type Result<T> = std::result::Result<T, Error>;
14+
#[derive(Debug, Error)]
1215
pub enum Error {
16+
#[error("{0}")]
1317
Other(String),
18+
#[error("Invalid input")]
1419
InvalidInput,
1520
}

0 commit comments

Comments
 (0)