diff options
| author | Mroik <mroik@delayed.space> | 2025-01-29 20:45:40 +0100 |
|---|---|---|
| committer | Mroik <mroik@delayed.space> | 2025-02-01 19:34:40 +0100 |
| commit | a088fb39422100c13d825e2220acb3282d8bd5e0 (patch) | |
| tree | b43753669fe7946a7526005e2a694e22480b6cc5 /src/error.rs | |
| parent | 362e92b27e64be1b2a5d8d9d46f2195a51051001 (diff) | |
Move error logic into its own crate
Diffstat (limited to 'src/error.rs')
| -rw-r--r-- | src/error.rs | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/src/error.rs b/src/error.rs new file mode 100644 index 0000000..0da2cf7 --- /dev/null +++ b/src/error.rs @@ -0,0 +1,23 @@ +use std::{error::Error, fmt::Display}; + +#[derive(Debug)] +pub struct WordTooLongError { + word: String, +} + +impl WordTooLongError { + pub fn new(word: impl Into<String>) -> WordTooLongError { + WordTooLongError { word: word.into() } + } +} + +impl Display for WordTooLongError { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + f.write_fmt(format_args!( + "The word \"{}\" is too long for the current terminal size", + self.word + )) + } +} + +impl Error for WordTooLongError {} |
