about summary refs log tree commit diff
path: root/src/lib.rs
diff options
context:
space:
mode:
authorGenny <gen@nyble.dev>2021-09-23 20:33:50 -0500
committerGenny <gen@nyble.dev>2021-09-23 20:33:50 -0500
commit637441239434fabedfe83f5abc1af4232c802f7a (patch)
treedbc84cd1a31686077fc046fd42d223f1ca08f890 /src/lib.rs
parent7b8081a79fb3db4a76f9e4cca8f8a88e6e7f873c (diff)
downloadgifed-637441239434fabedfe83f5abc1af4232c802f7a.tar.gz
gifed-637441239434fabedfe83f5abc1af4232c802f7a.zip
Improve API, monocommit, sorry
Diffstat (limited to 'src/lib.rs')
-rw-r--r--src/lib.rs27
1 files changed, 27 insertions, 0 deletions
diff --git a/src/lib.rs b/src/lib.rs
index 6c0203c..97bab10 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -6,6 +6,9 @@ pub mod block;
 pub mod reader;
 pub mod writer;
 
+use core::fmt;
+use std::error::Error;
+
 pub use color::Color;
 pub use gif::Gif;
 pub use lzw::LZW;
@@ -20,3 +23,27 @@ pub(crate) fn packed_to_color_table_length(packed: u8) -> usize {
 //in 87a aren't set if version is 87a, or that we return a warning, etc. Just
 //remember about this.
 //bottom of page 24 in 89a
+
+#[derive(Clone, Copy, Debug)]
+pub enum EncodingError {
+    TooManyColors,
+    NoColorTable,
+    IndicieSizeMismatch { expected: usize, got: usize },
+}
+
+impl fmt::Display for EncodingError {
+    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
+        match self {
+            Self::TooManyColors => write!(f, "A palette is limited to 256 colors"),
+            Self::NoColorTable => write!(
+                f,
+                "Refusing to set the background color index when no color table is set!"
+            ),
+            Self::IndicieSizeMismatch { expected, got } => {
+                write!(f, "Expected to have {} indicies but got {}", expected, got)
+            }
+        }
+    }
+}
+
+impl Error for EncodingError {}