dsi_bitstream/traits/
words.rs1use core::error::Error;
10
11use common_traits::*;
12
13pub trait Word: UnsignedInt + ToBytes + FromBytes + FiniteRangeNumber {}
16impl<W: UnsignedInt + ToBytes + FromBytes + FiniteRangeNumber> Word for W {}
17
18pub trait WordRead {
20 type Error: Error + Send + Sync + 'static;
21
22 type Word: Word;
24
25 fn read_word(&mut self) -> Result<Self::Word, Self::Error>;
27}
28
29pub trait WordWrite {
31 type Error: Error + Send + Sync + 'static;
32
33 type Word: Word;
35
36 fn write_word(&mut self, word: Self::Word) -> Result<(), Self::Error>;
38
39 fn flush(&mut self) -> Result<(), Self::Error>;
41}
42
43pub trait WordSeek {
45 type Error: Error + Send + Sync + 'static;
46 fn word_pos(&mut self) -> Result<u64, Self::Error>;
48
49 fn set_word_pos(&mut self, word_pos: u64) -> Result<(), Self::Error>;
51}
52
53#[derive(Debug, Clone, PartialEq)]
54pub enum WordError {
56 UnexpectedEof { word_pos: usize },
57}
58
59impl core::error::Error for WordError {}
60impl core::fmt::Display for WordError {
61 fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
62 match self {
63 WordError::UnexpectedEof { word_pos } => {
64 write!(f, "Unexpected end of data at word position {}", word_pos)
65 }
66 }
67 }
68}