diff options
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 {} |
