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