qubit_io_binary/stream/
methods.rs1use std::io::Result;
11use std::io::SeekFrom;
12
13use qubit_io::Input;
14use qubit_io::Output;
15use qubit_io::Seekable;
16
17use super::BinaryReader;
18use super::BinaryWriter;
19use super::BufferedBinaryReader;
20use super::BufferedBinaryWriter;
21use super::BufferedLeb128Reader;
22use super::BufferedLeb128Writer;
23use super::BufferedZigZagReader;
24use super::BufferedZigZagWriter;
25use super::Leb128Reader;
26use super::Leb128Writer;
27use super::ZigZagReader;
28use super::ZigZagWriter;
29
30macro_rules! impl_input_methods {
31 ($type:ident<$($param:ident),+> where $($bound:tt)*) => {
32 impl<$($param),+> $type<$($param),+>
33 where
34 $($bound)*
35 {
36 #[inline(always)]
38 pub fn is_buffered(&self) -> bool {
39 Input::is_buffered(self)
40 }
41
42 #[inline(always)]
48 pub unsafe fn read_unchecked(
49 &mut self,
50 output: &mut [u8],
51 index: usize,
52 count: usize,
53 ) -> Result<usize> {
54 unsafe { Input::read_unchecked(self, output, index, count) }
56 }
57
58 #[inline(always)]
60 pub fn read(&mut self, output: &mut [u8]) -> Result<usize> {
61 Input::read(self, output)
62 }
63
64 #[inline(always)]
70 pub unsafe fn read_fully_unchecked(
71 &mut self,
72 output: &mut [u8],
73 index: usize,
74 count: usize,
75 ) -> Result<usize> {
76 unsafe { Input::read_fully_unchecked(self, output, index, count) }
78 }
79
80 #[inline(always)]
82 pub fn read_fully(&mut self, output: &mut [u8]) -> Result<usize> {
83 Input::read_fully(self, output)
84 }
85
86 #[inline(always)]
88 pub fn read_exactly(&mut self, output: &mut [u8]) -> Result<()> {
89 Input::read_exactly(self, output)
90 }
91 }
92 };
93}
94
95macro_rules! impl_output_methods {
96 ($type:ident<$($param:ident),+> where $($bound:tt)*) => {
97 impl<$($param),+> $type<$($param),+>
98 where
99 $($bound)*
100 {
101 #[inline(always)]
103 pub fn is_buffered(&self) -> bool {
104 Output::is_buffered(self)
105 }
106
107 #[inline(always)]
113 pub unsafe fn write_unchecked(
114 &mut self,
115 input: &[u8],
116 index: usize,
117 count: usize,
118 ) -> Result<usize> {
119 unsafe { Output::write_unchecked(self, input, index, count) }
121 }
122
123 #[inline(always)]
125 pub fn write(&mut self, input: &[u8]) -> Result<usize> {
126 Output::write(self, input)
127 }
128
129 #[inline(always)]
135 pub unsafe fn write_fully_unchecked(
136 &mut self,
137 input: &[u8],
138 index: usize,
139 count: usize,
140 ) -> Result<()> {
141 unsafe { Output::write_fully_unchecked(self, input, index, count) }
143 }
144
145 #[inline(always)]
147 pub fn write_fully(&mut self, input: &[u8]) -> Result<()> {
148 Output::write_fully(self, input)
149 }
150
151 #[inline(always)]
153 pub fn flush(&mut self) -> Result<()> {
154 Output::flush(self)
155 }
156 }
157 };
158}
159
160macro_rules! impl_seekable_methods {
161 ($type:ident<$($param:ident),+> where $($bound:tt)*) => {
162 impl<$($param),+> $type<$($param),+>
163 where
164 $($bound)*
165 {
166 #[inline(always)]
168 pub fn seek_to(&mut self, position: SeekFrom) -> Result<u64> {
169 Seekable::seek_to(self, position)
170 }
171 }
172 };
173}
174
175impl_input_methods!(BinaryReader<R, O> where R: Input<Item = u8>);
176impl_input_methods!(BufferedBinaryReader<R, O> where R: Input<Item = u8>);
177impl_input_methods!(Leb128Reader<R, P> where R: Input<Item = u8>);
178impl_input_methods!(BufferedLeb128Reader<R, P> where R: Input<Item = u8>);
179impl_input_methods!(ZigZagReader<R, P> where R: Input<Item = u8>);
180impl_input_methods!(BufferedZigZagReader<R, P> where R: Input<Item = u8>);
181
182impl_output_methods!(BinaryWriter<W, O> where W: Output<Item = u8>);
183impl_output_methods!(BufferedBinaryWriter<W, O> where W: Output<Item = u8>);
184impl_output_methods!(Leb128Writer<W> where W: Output<Item = u8>);
185impl_output_methods!(BufferedLeb128Writer<W> where W: Output<Item = u8>);
186impl_output_methods!(ZigZagWriter<W> where W: Output<Item = u8>);
187impl_output_methods!(BufferedZigZagWriter<W> where W: Output<Item = u8>);
188
189impl_seekable_methods!(BinaryReader<R, O> where R: Seekable<Unit = u8>);
190impl_seekable_methods!(BufferedBinaryReader<R, O> where R: Input<Item = u8> + Seekable<Unit = u8>);
191impl_seekable_methods!(Leb128Reader<R, P> where R: Seekable<Unit = u8>);
192impl_seekable_methods!(BufferedLeb128Reader<R, P> where R: Input<Item = u8> + Seekable<Unit = u8>);
193impl_seekable_methods!(ZigZagReader<R, P> where R: Seekable<Unit = u8>);
194impl_seekable_methods!(BufferedZigZagReader<R, P> where R: Input<Item = u8> + Seekable<Unit = u8>);
195impl_seekable_methods!(BinaryWriter<W, O> where W: Seekable<Unit = u8>);
196impl_seekable_methods!(BufferedBinaryWriter<W, O> where W: Output<Item = u8> + Seekable<Unit = u8>);
197impl_seekable_methods!(Leb128Writer<W> where W: Seekable<Unit = u8>);
198impl_seekable_methods!(BufferedLeb128Writer<W> where W: Output<Item = u8> + Seekable<Unit = u8>);
199impl_seekable_methods!(ZigZagWriter<W> where W: Seekable<Unit = u8>);
200impl_seekable_methods!(BufferedZigZagWriter<W> where W: Output<Item = u8> + Seekable<Unit = u8>);