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