1 /// The result of a coding operation on a pair of buffer. 2 #[must_use = "Contains a status with potential error information"] 3 pub struct BufferResult { 4 /// The number of bytes consumed from the input buffer. 5 pub consumed_in: usize, 6 /// The number of bytes written into the output buffer. 7 pub consumed_out: usize, 8 /// The status after returning from the write call. 9 pub status: Result<LzwStatus, LzwError>, 10 } 11 12 /// The result of a coding operation into a vector. 13 #[must_use = "Contains a status with potential error information"] 14 pub struct VectorResult { 15 /// The number of bytes consumed from the input buffer. 16 pub consumed_in: usize, 17 /// The number of bytes written into the output buffer. 18 pub consumed_out: usize, 19 /// The status after returning from the write call. 20 pub status: Result<LzwStatus, LzwError>, 21 } 22 23 /// The result of coding into an output stream. 24 #[cfg(feature = "std")] 25 #[must_use = "Contains a status with potential error information"] 26 pub struct StreamResult { 27 /// The total number of bytes consumed from the reader. 28 pub bytes_read: usize, 29 /// The total number of bytes written into the writer. 30 pub bytes_written: usize, 31 /// The possible error that occurred. 32 /// 33 /// Note that when writing into streams it is not in general possible to recover from an error. 34 pub status: std::io::Result<()>, 35 } 36 37 /// The status after successful coding of an LZW stream. 38 #[derive(Debug, Clone, Copy)] 39 pub enum LzwStatus { 40 /// Everything went well. 41 Ok, 42 /// No bytes were read or written and no internal state advanced. 43 /// 44 /// If this is returned but your application can not provide more input data then decoding is 45 /// definitely stuck for good and it should stop trying and report some error of its own. In 46 /// other situations this may be used as a signal to refill an internal buffer. 47 NoProgress, 48 /// No more data will be produced because an end marker was reached. 49 Done, 50 } 51 52 /// The error kind after unsuccessful coding of an LZW stream. 53 #[derive(Debug, Clone, Copy)] 54 pub enum LzwError { 55 /// The input contained an invalid code. 56 /// 57 /// For decompression this refers to a code larger than those currently known through the prior 58 /// decoding stages. For compression this refers to a byte that has no code representation due 59 /// to being larger than permitted by the `size` parameter given to the Encoder. 60 InvalidCode, 61 } 62 63 impl core::fmt::Display for LzwError { fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result64 fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result { 65 match self { 66 LzwError::InvalidCode => f.write_str("invalid code in LZW stream"), 67 } 68 } 69 } 70 71 #[cfg(feature = "std")] 72 impl std::error::Error for LzwError {} 73