/rust/registry/src/index.crates.io-1949cf8c6b5b557f/lebe-0.5.3/src/lib.rs
Line | Count | Source |
1 | | #![warn( |
2 | | missing_docs, unused, |
3 | | trivial_numeric_casts, |
4 | | future_incompatible, |
5 | | rust_2018_compatibility, |
6 | | rust_2018_idioms, |
7 | | clippy::all |
8 | | )] |
9 | | |
10 | | #![doc(html_root_url = "https://docs.rs/lebe/0.5.0")] |
11 | | |
12 | | //! Dead simple endianness conversions. |
13 | | //! The following operations are implemented on |
14 | | //! `u8`, `i8`, `u16`, `i16`, `u32`, `i32`, `u64`, `i64`, `u128`, `i128`, `f32`, `f64`: |
15 | | //! |
16 | | //! |
17 | | //! ### Read Numbers |
18 | | //! ```rust |
19 | | //! use lebe::prelude::*; |
20 | | //! let mut reader: &[u8] = &[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15]; |
21 | | //! |
22 | | //! let number : u64 = reader.read_from_little_endian()?; |
23 | | //! let number = u64::read_from_big_endian(&mut reader)?; |
24 | | //! # Ok::<(), std::io::Error>(()) |
25 | | //! ``` |
26 | | //! |
27 | | //! ### Read Slices |
28 | | //! ```rust |
29 | | //! use std::io::Read; |
30 | | //! use lebe::prelude::*; |
31 | | //! let mut reader: &[u8] = &[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15]; |
32 | | //! |
33 | | //! let mut numbers: &mut [u64] = &mut [0, 0]; |
34 | | //! reader.read_from_little_endian_into(numbers)?; |
35 | | //! # Ok::<(), std::io::Error>(()) |
36 | | //! ``` |
37 | | //! |
38 | | //! ### Write Numbers |
39 | | //! ```rust |
40 | | //! use std::io::Read; |
41 | | //! use lebe::prelude::*; |
42 | | //! let mut writer: Vec<u8> = Vec::new(); |
43 | | //! |
44 | | //! let number: u64 = 1237691; |
45 | | //! writer.write_as_big_endian(&number)?; |
46 | | //! # Ok::<(), std::io::Error>(()) |
47 | | //! ``` |
48 | | //! |
49 | | //! ### Write Slices |
50 | | //! ```rust |
51 | | //! use std::io::Write; |
52 | | //! use lebe::prelude::*; |
53 | | //! let mut writer: Vec<u8> = Vec::new(); |
54 | | //! |
55 | | //! let numbers: &[u64] = &[1_u64, 234545_u64]; |
56 | | //! writer.write_as_little_endian(numbers)?; |
57 | | //! # Ok::<(), std::io::Error>(()) |
58 | | //! ``` |
59 | | //! |
60 | | |
61 | | |
62 | | /// Exports some of the most common types. |
63 | | pub mod prelude { |
64 | | pub use super::Endian; |
65 | | pub use super::io::{ WriteEndian, ReadEndian, ReadPrimitive }; |
66 | | } |
67 | | |
68 | | /// Represents values that can swap their bytes to reverse their endianness. |
69 | | /// |
70 | | /// Supports converting values in-place using [`swap_bytes`] or [`convert_current_to_little_endian`]: |
71 | | /// Supports converting while transferring ownership using |
72 | | /// [`from_little_endian_into_current`] or [`from_current_into_little_endian`]. |
73 | | /// |
74 | | /// |
75 | | /// For the types `u8`, `i8`, `&[u8]` and `&[i8]`, this trait will never transform any data, |
76 | | /// as they are just implemented for completeness. |
77 | | pub trait Endian { |
78 | | |
79 | | /// Swaps all bytes in this value, inverting its endianness. |
80 | | fn swap_bytes(&mut self); |
81 | | |
82 | | /// On a little endian machine, this does nothing. |
83 | | /// On a big endian machine, the bytes of this value are reversed. |
84 | 229M | #[inline] fn convert_current_to_little_endian(&mut self) { |
85 | | #[cfg(target_endian = "big")] { |
86 | | self.swap_bytes(); |
87 | | } |
88 | 229M | } <i32 as lebe::Endian>::convert_current_to_little_endian Line | Count | Source | 84 | 3.61M | #[inline] fn convert_current_to_little_endian(&mut self) { | 85 | | #[cfg(target_endian = "big")] { | 86 | | self.swap_bytes(); | 87 | | } | 88 | 3.61M | } |
<u32 as lebe::Endian>::convert_current_to_little_endian Line | Count | Source | 84 | 234 | #[inline] fn convert_current_to_little_endian(&mut self) { | 85 | | #[cfg(target_endian = "big")] { | 86 | | self.swap_bytes(); | 87 | | } | 88 | 234 | } |
<u16 as lebe::Endian>::convert_current_to_little_endian Line | Count | Source | 84 | 1.40M | #[inline] fn convert_current_to_little_endian(&mut self) { | 85 | | #[cfg(target_endian = "big")] { | 86 | | self.swap_bytes(); | 87 | | } | 88 | 1.40M | } |
Unexecuted instantiation: <_ as lebe::Endian>::convert_current_to_little_endian Unexecuted instantiation: <f64 as lebe::Endian>::convert_current_to_little_endian Unexecuted instantiation: <f32 as lebe::Endian>::convert_current_to_little_endian Unexecuted instantiation: <u8 as lebe::Endian>::convert_current_to_little_endian Unexecuted instantiation: <u64 as lebe::Endian>::convert_current_to_little_endian Unexecuted instantiation: <f64 as lebe::Endian>::convert_current_to_little_endian <f32 as lebe::Endian>::convert_current_to_little_endian Line | Count | Source | 84 | 224M | #[inline] fn convert_current_to_little_endian(&mut self) { | 85 | | #[cfg(target_endian = "big")] { | 86 | | self.swap_bytes(); | 87 | | } | 88 | 224M | } |
<u8 as lebe::Endian>::convert_current_to_little_endian Line | Count | Source | 84 | 2.73k | #[inline] fn convert_current_to_little_endian(&mut self) { | 85 | | #[cfg(target_endian = "big")] { | 86 | | self.swap_bytes(); | 87 | | } | 88 | 2.73k | } |
Unexecuted instantiation: <u64 as lebe::Endian>::convert_current_to_little_endian |
89 | | |
90 | | /// On a big endian machine, this does nothing. |
91 | | /// On a little endian machine, the bytes of this value are reversed. |
92 | 0 | #[inline] fn convert_current_to_big_endian(&mut self) { |
93 | 0 | #[cfg(target_endian = "little")] { |
94 | 0 | self.swap_bytes(); |
95 | 0 | } |
96 | 0 | } |
97 | | |
98 | | /// On a little endian machine, this does nothing. |
99 | | /// On a big endian machine, the bytes of this value are reversed. |
100 | 125M | #[inline] fn convert_little_endian_to_current(&mut self) { |
101 | | #[cfg(target_endian = "big")] { |
102 | | self.swap_bytes(); |
103 | | } |
104 | 125M | } <[i8] as lebe::Endian>::convert_little_endian_to_current Line | Count | Source | 100 | 199k | #[inline] fn convert_little_endian_to_current(&mut self) { | 101 | | #[cfg(target_endian = "big")] { | 102 | | self.swap_bytes(); | 103 | | } | 104 | 199k | } |
<[u64] as lebe::Endian>::convert_little_endian_to_current Line | Count | Source | 100 | 16.9k | #[inline] fn convert_little_endian_to_current(&mut self) { | 101 | | #[cfg(target_endian = "big")] { | 102 | | self.swap_bytes(); | 103 | | } | 104 | 16.9k | } |
<f64 as lebe::Endian>::convert_little_endian_to_current Line | Count | Source | 100 | 2.91k | #[inline] fn convert_little_endian_to_current(&mut self) { | 101 | | #[cfg(target_endian = "big")] { | 102 | | self.swap_bytes(); | 103 | | } | 104 | 2.91k | } |
Unexecuted instantiation: <u64 as lebe::Endian>::convert_little_endian_to_current <[f32] as lebe::Endian>::convert_little_endian_to_current Line | Count | Source | 100 | 66.6M | #[inline] fn convert_little_endian_to_current(&mut self) { | 101 | | #[cfg(target_endian = "big")] { | 102 | | self.swap_bytes(); | 103 | | } | 104 | 66.6M | } |
<[u8] as lebe::Endian>::convert_little_endian_to_current Line | Count | Source | 100 | 2.50M | #[inline] fn convert_little_endian_to_current(&mut self) { | 101 | | #[cfg(target_endian = "big")] { | 102 | | self.swap_bytes(); | 103 | | } | 104 | 2.50M | } |
<[u32] as lebe::Endian>::convert_little_endian_to_current Line | Count | Source | 100 | 64.9k | #[inline] fn convert_little_endian_to_current(&mut self) { | 101 | | #[cfg(target_endian = "big")] { | 102 | | self.swap_bytes(); | 103 | | } | 104 | 64.9k | } |
<[u16] as lebe::Endian>::convert_little_endian_to_current Line | Count | Source | 100 | 127k | #[inline] fn convert_little_endian_to_current(&mut self) { | 101 | | #[cfg(target_endian = "big")] { | 102 | | self.swap_bytes(); | 103 | | } | 104 | 127k | } |
<f32 as lebe::Endian>::convert_little_endian_to_current Line | Count | Source | 100 | 342k | #[inline] fn convert_little_endian_to_current(&mut self) { | 101 | | #[cfg(target_endian = "big")] { | 102 | | self.swap_bytes(); | 103 | | } | 104 | 342k | } |
<u8 as lebe::Endian>::convert_little_endian_to_current Line | Count | Source | 100 | 47.4M | #[inline] fn convert_little_endian_to_current(&mut self) { | 101 | | #[cfg(target_endian = "big")] { | 102 | | self.swap_bytes(); | 103 | | } | 104 | 47.4M | } |
<i32 as lebe::Endian>::convert_little_endian_to_current Line | Count | Source | 100 | 6.84M | #[inline] fn convert_little_endian_to_current(&mut self) { | 101 | | #[cfg(target_endian = "big")] { | 102 | | self.swap_bytes(); | 103 | | } | 104 | 6.84M | } |
<u32 as lebe::Endian>::convert_little_endian_to_current Line | Count | Source | 100 | 142k | #[inline] fn convert_little_endian_to_current(&mut self) { | 101 | | #[cfg(target_endian = "big")] { | 102 | | self.swap_bytes(); | 103 | | } | 104 | 142k | } |
<u16 as lebe::Endian>::convert_little_endian_to_current Line | Count | Source | 100 | 1.40M | #[inline] fn convert_little_endian_to_current(&mut self) { | 101 | | #[cfg(target_endian = "big")] { | 102 | | self.swap_bytes(); | 103 | | } | 104 | 1.40M | } |
Unexecuted instantiation: <_ as lebe::Endian>::convert_little_endian_to_current |
105 | | |
106 | | /// On a big endian machine, this does nothing. |
107 | | /// On a little endian machine, the bytes of this value are reversed. |
108 | 0 | #[inline] fn convert_big_endian_to_current(&mut self) { |
109 | 0 | #[cfg(target_endian = "little")] { |
110 | 0 | self.swap_bytes(); |
111 | 0 | } |
112 | 0 | } |
113 | | |
114 | | /// On a little endian machine, this does nothing. |
115 | | /// On a big endian machine, the bytes of this value are reversed. |
116 | 229M | #[inline] fn from_current_into_little_endian(mut self) -> Self where Self: Sized { |
117 | 229M | self.convert_current_to_little_endian(); |
118 | 229M | self |
119 | 229M | } <i32 as lebe::Endian>::from_current_into_little_endian Line | Count | Source | 116 | 3.61M | #[inline] fn from_current_into_little_endian(mut self) -> Self where Self: Sized { | 117 | 3.61M | self.convert_current_to_little_endian(); | 118 | 3.61M | self | 119 | 3.61M | } |
<u32 as lebe::Endian>::from_current_into_little_endian Line | Count | Source | 116 | 234 | #[inline] fn from_current_into_little_endian(mut self) -> Self where Self: Sized { | 117 | 234 | self.convert_current_to_little_endian(); | 118 | 234 | self | 119 | 234 | } |
<u16 as lebe::Endian>::from_current_into_little_endian Line | Count | Source | 116 | 1.40M | #[inline] fn from_current_into_little_endian(mut self) -> Self where Self: Sized { | 117 | 1.40M | self.convert_current_to_little_endian(); | 118 | 1.40M | self | 119 | 1.40M | } |
Unexecuted instantiation: <_ as lebe::Endian>::from_current_into_little_endian Unexecuted instantiation: <f64 as lebe::Endian>::from_current_into_little_endian Unexecuted instantiation: <f32 as lebe::Endian>::from_current_into_little_endian Unexecuted instantiation: <u8 as lebe::Endian>::from_current_into_little_endian Unexecuted instantiation: <u64 as lebe::Endian>::from_current_into_little_endian Unexecuted instantiation: <f64 as lebe::Endian>::from_current_into_little_endian <f32 as lebe::Endian>::from_current_into_little_endian Line | Count | Source | 116 | 224M | #[inline] fn from_current_into_little_endian(mut self) -> Self where Self: Sized { | 117 | 224M | self.convert_current_to_little_endian(); | 118 | 224M | self | 119 | 224M | } |
<u8 as lebe::Endian>::from_current_into_little_endian Line | Count | Source | 116 | 2.73k | #[inline] fn from_current_into_little_endian(mut self) -> Self where Self: Sized { | 117 | 2.73k | self.convert_current_to_little_endian(); | 118 | 2.73k | self | 119 | 2.73k | } |
Unexecuted instantiation: <u64 as lebe::Endian>::from_current_into_little_endian |
120 | | |
121 | | /// On a big endian machine, this does nothing. |
122 | | /// On a little endian machine, the bytes of this value are reversed. |
123 | 0 | #[inline] fn from_current_into_big_endian(mut self) -> Self where Self: Sized { |
124 | 0 | self.convert_current_to_big_endian(); |
125 | 0 | self |
126 | 0 | } |
127 | | |
128 | | /// On a little endian machine, this does nothing. |
129 | | /// On a big endian machine, the bytes of this value are reversed. |
130 | 0 | #[inline] fn from_little_endian_into_current(mut self) -> Self where Self: Sized { |
131 | 0 | self.convert_little_endian_to_current(); |
132 | 0 | self |
133 | 0 | } |
134 | | |
135 | | /// On a big endian machine, this does nothing. |
136 | | /// On a little endian machine, the bytes of this value are reversed. |
137 | 0 | #[inline] fn from_big_endian_into_current(mut self) -> Self where Self: Sized { |
138 | 0 | self.convert_big_endian_to_current(); |
139 | 0 | self |
140 | 0 | } |
141 | | } |
142 | | |
143 | | |
144 | | // call a macro for each argument |
145 | | macro_rules! call_single_arg_macro_for_each { |
146 | | ($macro: ident, $( $arguments: ident ),* ) => { |
147 | | $( $macro! { $arguments } )* |
148 | | }; |
149 | | } |
150 | | |
151 | | // implement this interface for primitive signed and unsigned integers |
152 | | macro_rules! implement_simple_primitive_endian { |
153 | | ($type: ident) => { |
154 | | impl Endian for $type { |
155 | 0 | fn swap_bytes(&mut self) { |
156 | 0 | *self = $type::swap_bytes(*self); |
157 | 0 | } Unexecuted instantiation: <u16 as lebe::Endian>::swap_bytes Unexecuted instantiation: <u32 as lebe::Endian>::swap_bytes Unexecuted instantiation: <u64 as lebe::Endian>::swap_bytes Unexecuted instantiation: <u128 as lebe::Endian>::swap_bytes Unexecuted instantiation: <i16 as lebe::Endian>::swap_bytes Unexecuted instantiation: <i32 as lebe::Endian>::swap_bytes Unexecuted instantiation: <i64 as lebe::Endian>::swap_bytes Unexecuted instantiation: <i128 as lebe::Endian>::swap_bytes |
158 | | } |
159 | | }; |
160 | | } |
161 | | |
162 | | |
163 | | call_single_arg_macro_for_each! { |
164 | | implement_simple_primitive_endian, |
165 | | u16, u32, u64, u128, i16, i32, i64, i128 |
166 | | } |
167 | | |
168 | | // no-op implementations |
169 | 0 | impl Endian for u8 { fn swap_bytes(&mut self) {} } |
170 | 0 | impl Endian for i8 { fn swap_bytes(&mut self) {} } |
171 | 0 | impl Endian for [u8] { fn swap_bytes(&mut self) {} } |
172 | 0 | impl Endian for [i8] { fn swap_bytes(&mut self) {} } |
173 | | |
174 | | // implement this interface for primitive floats, because they do not have a `swap_bytes()` in `std` |
175 | | macro_rules! implement_float_primitive_by_bits { |
176 | | ($type: ident) => { |
177 | | impl Endian for $type { |
178 | 0 | fn swap_bytes(&mut self) { |
179 | 0 | *self = Self::from_bits(self.to_bits().swap_bytes()); |
180 | 0 | } Unexecuted instantiation: <f32 as lebe::Endian>::swap_bytes Unexecuted instantiation: <f64 as lebe::Endian>::swap_bytes |
181 | | } |
182 | | }; |
183 | | } |
184 | | |
185 | | |
186 | | implement_float_primitive_by_bits!(f32); |
187 | | implement_float_primitive_by_bits!(f64); |
188 | | |
189 | | macro_rules! implement_slice_by_element { |
190 | | ($type: ident) => { |
191 | | impl Endian for [$type] { |
192 | 0 | fn swap_bytes(&mut self) { |
193 | 0 | for number in self.iter_mut() { // TODO SIMD? |
194 | 0 | number.swap_bytes(); |
195 | 0 | } |
196 | 0 | } Unexecuted instantiation: <[u16] as lebe::Endian>::swap_bytes Unexecuted instantiation: <[u32] as lebe::Endian>::swap_bytes Unexecuted instantiation: <[u64] as lebe::Endian>::swap_bytes Unexecuted instantiation: <[u128] as lebe::Endian>::swap_bytes Unexecuted instantiation: <[i16] as lebe::Endian>::swap_bytes Unexecuted instantiation: <[i32] as lebe::Endian>::swap_bytes Unexecuted instantiation: <[i64] as lebe::Endian>::swap_bytes Unexecuted instantiation: <[i128] as lebe::Endian>::swap_bytes Unexecuted instantiation: <[f64] as lebe::Endian>::swap_bytes Unexecuted instantiation: <[f32] as lebe::Endian>::swap_bytes |
197 | | } |
198 | | }; |
199 | | } |
200 | | |
201 | | call_single_arg_macro_for_each! { |
202 | | implement_slice_by_element, |
203 | | u16, u32, u64, u128, |
204 | | i16, i32, i64, i128, |
205 | | f64, f32 |
206 | | } |
207 | | |
208 | | /// Easily write primitives and slices of primitives to |
209 | | /// binary `std::io::Write` streams and easily read from binary `std::io::Read` streams. |
210 | | /// |
211 | | /// Also contains the unsafe `bytes` module for reinterpreting values as byte slices and vice versa. |
212 | | pub mod io { |
213 | | use super::Endian; |
214 | | use std::io::{Read, Write, Result}; |
215 | | |
216 | | /// Reinterpret values as byte slices and byte slices as values unsafely. |
217 | | pub mod bytes { |
218 | | use std::io::{Read, Write, Result}; |
219 | | |
220 | | /// View this slice of values as a slice of bytes. |
221 | | #[inline] |
222 | 3.35M | pub unsafe fn slice_as_bytes<T>(value: &[T]) -> &[u8] { |
223 | 3.35M | std::slice::from_raw_parts( |
224 | 3.35M | value.as_ptr() as *const u8, |
225 | 3.35M | value.len() * std::mem::size_of::<T>() |
226 | 3.35M | ) |
227 | 3.35M | } Unexecuted instantiation: lebe::io::bytes::slice_as_bytes::<f32> lebe::io::bytes::slice_as_bytes::<u8> Line | Count | Source | 222 | 725k | pub unsafe fn slice_as_bytes<T>(value: &[T]) -> &[u8] { | 223 | 725k | std::slice::from_raw_parts( | 224 | 725k | value.as_ptr() as *const u8, | 225 | 725k | value.len() * std::mem::size_of::<T>() | 226 | 725k | ) | 227 | 725k | } |
Unexecuted instantiation: lebe::io::bytes::slice_as_bytes::<u32> lebe::io::bytes::slice_as_bytes::<u16> Line | Count | Source | 222 | 2.63M | pub unsafe fn slice_as_bytes<T>(value: &[T]) -> &[u8] { | 223 | 2.63M | std::slice::from_raw_parts( | 224 | 2.63M | value.as_ptr() as *const u8, | 225 | 2.63M | value.len() * std::mem::size_of::<T>() | 226 | 2.63M | ) | 227 | 2.63M | } |
Unexecuted instantiation: lebe::io::bytes::slice_as_bytes::<_> Unexecuted instantiation: lebe::io::bytes::slice_as_bytes::<i8> Unexecuted instantiation: lebe::io::bytes::slice_as_bytes::<u64> lebe::io::bytes::slice_as_bytes::<i8> Line | Count | Source | 222 | 312 | pub unsafe fn slice_as_bytes<T>(value: &[T]) -> &[u8] { | 223 | 312 | std::slice::from_raw_parts( | 224 | 312 | value.as_ptr() as *const u8, | 225 | 312 | value.len() * std::mem::size_of::<T>() | 226 | 312 | ) | 227 | 312 | } |
lebe::io::bytes::slice_as_bytes::<u64> Line | Count | Source | 222 | 78 | pub unsafe fn slice_as_bytes<T>(value: &[T]) -> &[u8] { | 223 | 78 | std::slice::from_raw_parts( | 224 | 78 | value.as_ptr() as *const u8, | 225 | 78 | value.len() * std::mem::size_of::<T>() | 226 | 78 | ) | 227 | 78 | } |
|
228 | | |
229 | | /// View this slice of values as a mutable slice of bytes. |
230 | | #[inline] |
231 | 69.5M | pub unsafe fn slice_as_bytes_mut<T>(value: &mut [T]) -> &mut [u8] { |
232 | 69.5M | std::slice::from_raw_parts_mut( |
233 | 69.5M | value.as_mut_ptr() as *mut u8, |
234 | 69.5M | value.len() * std::mem::size_of::<T>() |
235 | 69.5M | ) |
236 | 69.5M | } lebe::io::bytes::slice_as_bytes_mut::<i8> Line | Count | Source | 231 | 199k | pub unsafe fn slice_as_bytes_mut<T>(value: &mut [T]) -> &mut [u8] { | 232 | 199k | std::slice::from_raw_parts_mut( | 233 | 199k | value.as_mut_ptr() as *mut u8, | 234 | 199k | value.len() * std::mem::size_of::<T>() | 235 | 199k | ) | 236 | 199k | } |
lebe::io::bytes::slice_as_bytes_mut::<u64> Line | Count | Source | 231 | 17.2k | pub unsafe fn slice_as_bytes_mut<T>(value: &mut [T]) -> &mut [u8] { | 232 | 17.2k | std::slice::from_raw_parts_mut( | 233 | 17.2k | value.as_mut_ptr() as *mut u8, | 234 | 17.2k | value.len() * std::mem::size_of::<T>() | 235 | 17.2k | ) | 236 | 17.2k | } |
lebe::io::bytes::slice_as_bytes_mut::<f32> Line | Count | Source | 231 | 66.6M | pub unsafe fn slice_as_bytes_mut<T>(value: &mut [T]) -> &mut [u8] { | 232 | 66.6M | std::slice::from_raw_parts_mut( | 233 | 66.6M | value.as_mut_ptr() as *mut u8, | 234 | 66.6M | value.len() * std::mem::size_of::<T>() | 235 | 66.6M | ) | 236 | 66.6M | } |
lebe::io::bytes::slice_as_bytes_mut::<u8> Line | Count | Source | 231 | 2.50M | pub unsafe fn slice_as_bytes_mut<T>(value: &mut [T]) -> &mut [u8] { | 232 | 2.50M | std::slice::from_raw_parts_mut( | 233 | 2.50M | value.as_mut_ptr() as *mut u8, | 234 | 2.50M | value.len() * std::mem::size_of::<T>() | 235 | 2.50M | ) | 236 | 2.50M | } |
lebe::io::bytes::slice_as_bytes_mut::<u32> Line | Count | Source | 231 | 64.9k | pub unsafe fn slice_as_bytes_mut<T>(value: &mut [T]) -> &mut [u8] { | 232 | 64.9k | std::slice::from_raw_parts_mut( | 233 | 64.9k | value.as_mut_ptr() as *mut u8, | 234 | 64.9k | value.len() * std::mem::size_of::<T>() | 235 | 64.9k | ) | 236 | 64.9k | } |
lebe::io::bytes::slice_as_bytes_mut::<u16> Line | Count | Source | 231 | 127k | pub unsafe fn slice_as_bytes_mut<T>(value: &mut [T]) -> &mut [u8] { | 232 | 127k | std::slice::from_raw_parts_mut( | 233 | 127k | value.as_mut_ptr() as *mut u8, | 234 | 127k | value.len() * std::mem::size_of::<T>() | 235 | 127k | ) | 236 | 127k | } |
Unexecuted instantiation: lebe::io::bytes::slice_as_bytes_mut::<_> |
237 | | |
238 | | /// View this reference as a slice of bytes. |
239 | | #[inline] |
240 | 229M | pub unsafe fn value_as_bytes<T: Sized>(value: &T) -> &[u8] { |
241 | 229M | std::slice::from_raw_parts( |
242 | 229M | value as *const T as *const u8, |
243 | 229M | std::mem::size_of::<T>() |
244 | 229M | ) |
245 | 229M | } lebe::io::bytes::value_as_bytes::<i32> Line | Count | Source | 240 | 3.61M | pub unsafe fn value_as_bytes<T: Sized>(value: &T) -> &[u8] { | 241 | 3.61M | std::slice::from_raw_parts( | 242 | 3.61M | value as *const T as *const u8, | 243 | 3.61M | std::mem::size_of::<T>() | 244 | 3.61M | ) | 245 | 3.61M | } |
lebe::io::bytes::value_as_bytes::<u32> Line | Count | Source | 240 | 234 | pub unsafe fn value_as_bytes<T: Sized>(value: &T) -> &[u8] { | 241 | 234 | std::slice::from_raw_parts( | 242 | 234 | value as *const T as *const u8, | 243 | 234 | std::mem::size_of::<T>() | 244 | 234 | ) | 245 | 234 | } |
lebe::io::bytes::value_as_bytes::<u16> Line | Count | Source | 240 | 1.40M | pub unsafe fn value_as_bytes<T: Sized>(value: &T) -> &[u8] { | 241 | 1.40M | std::slice::from_raw_parts( | 242 | 1.40M | value as *const T as *const u8, | 243 | 1.40M | std::mem::size_of::<T>() | 244 | 1.40M | ) | 245 | 1.40M | } |
Unexecuted instantiation: lebe::io::bytes::value_as_bytes::<_> Unexecuted instantiation: lebe::io::bytes::value_as_bytes::<f64> Unexecuted instantiation: lebe::io::bytes::value_as_bytes::<f32> Unexecuted instantiation: lebe::io::bytes::value_as_bytes::<u8> Unexecuted instantiation: lebe::io::bytes::value_as_bytes::<u64> Unexecuted instantiation: lebe::io::bytes::value_as_bytes::<f64> lebe::io::bytes::value_as_bytes::<f32> Line | Count | Source | 240 | 224M | pub unsafe fn value_as_bytes<T: Sized>(value: &T) -> &[u8] { | 241 | 224M | std::slice::from_raw_parts( | 242 | 224M | value as *const T as *const u8, | 243 | 224M | std::mem::size_of::<T>() | 244 | 224M | ) | 245 | 224M | } |
lebe::io::bytes::value_as_bytes::<u8> Line | Count | Source | 240 | 2.73k | pub unsafe fn value_as_bytes<T: Sized>(value: &T) -> &[u8] { | 241 | 2.73k | std::slice::from_raw_parts( | 242 | 2.73k | value as *const T as *const u8, | 243 | 2.73k | std::mem::size_of::<T>() | 244 | 2.73k | ) | 245 | 2.73k | } |
Unexecuted instantiation: lebe::io::bytes::value_as_bytes::<u64> |
246 | | |
247 | | /// View this reference as a mutable slice of bytes. |
248 | | #[inline] |
249 | 56.1M | pub unsafe fn value_as_bytes_mut<T: Sized>(value: &mut T) ->&mut [u8] { |
250 | 56.1M | std::slice::from_raw_parts_mut( |
251 | 56.1M | value as *mut T as *mut u8, |
252 | 56.1M | std::mem::size_of::<T>() |
253 | 56.1M | ) |
254 | 56.1M | } lebe::io::bytes::value_as_bytes_mut::<f64> Line | Count | Source | 249 | 2.91k | pub unsafe fn value_as_bytes_mut<T: Sized>(value: &mut T) ->&mut [u8] { | 250 | 2.91k | std::slice::from_raw_parts_mut( | 251 | 2.91k | value as *mut T as *mut u8, | 252 | 2.91k | std::mem::size_of::<T>() | 253 | 2.91k | ) | 254 | 2.91k | } |
Unexecuted instantiation: lebe::io::bytes::value_as_bytes_mut::<u64> lebe::io::bytes::value_as_bytes_mut::<f32> Line | Count | Source | 249 | 342k | pub unsafe fn value_as_bytes_mut<T: Sized>(value: &mut T) ->&mut [u8] { | 250 | 342k | std::slice::from_raw_parts_mut( | 251 | 342k | value as *mut T as *mut u8, | 252 | 342k | std::mem::size_of::<T>() | 253 | 342k | ) | 254 | 342k | } |
lebe::io::bytes::value_as_bytes_mut::<u8> Line | Count | Source | 249 | 47.4M | pub unsafe fn value_as_bytes_mut<T: Sized>(value: &mut T) ->&mut [u8] { | 250 | 47.4M | std::slice::from_raw_parts_mut( | 251 | 47.4M | value as *mut T as *mut u8, | 252 | 47.4M | std::mem::size_of::<T>() | 253 | 47.4M | ) | 254 | 47.4M | } |
lebe::io::bytes::value_as_bytes_mut::<i32> Line | Count | Source | 249 | 6.84M | pub unsafe fn value_as_bytes_mut<T: Sized>(value: &mut T) ->&mut [u8] { | 250 | 6.84M | std::slice::from_raw_parts_mut( | 251 | 6.84M | value as *mut T as *mut u8, | 252 | 6.84M | std::mem::size_of::<T>() | 253 | 6.84M | ) | 254 | 6.84M | } |
lebe::io::bytes::value_as_bytes_mut::<u32> Line | Count | Source | 249 | 142k | pub unsafe fn value_as_bytes_mut<T: Sized>(value: &mut T) ->&mut [u8] { | 250 | 142k | std::slice::from_raw_parts_mut( | 251 | 142k | value as *mut T as *mut u8, | 252 | 142k | std::mem::size_of::<T>() | 253 | 142k | ) | 254 | 142k | } |
lebe::io::bytes::value_as_bytes_mut::<u16> Line | Count | Source | 249 | 1.40M | pub unsafe fn value_as_bytes_mut<T: Sized>(value: &mut T) ->&mut [u8] { | 250 | 1.40M | std::slice::from_raw_parts_mut( | 251 | 1.40M | value as *mut T as *mut u8, | 252 | 1.40M | std::mem::size_of::<T>() | 253 | 1.40M | ) | 254 | 1.40M | } |
Unexecuted instantiation: lebe::io::bytes::value_as_bytes_mut::<_> |
255 | | |
256 | | /// View this slice as a mutable slice of bytes and write it. |
257 | | #[inline] |
258 | 3.35M | pub unsafe fn write_slice<T>(write: &mut impl Write, value: &[T]) -> Result<()> { |
259 | 3.35M | write.write_all(slice_as_bytes(value)) |
260 | 3.35M | } Unexecuted instantiation: lebe::io::bytes::write_slice::<f32, std::io::cursor::Cursor<&mut [u8]>> lebe::io::bytes::write_slice::<u8, alloc::vec::Vec<u8>> Line | Count | Source | 258 | 393 | pub unsafe fn write_slice<T>(write: &mut impl Write, value: &[T]) -> Result<()> { | 259 | 393 | write.write_all(slice_as_bytes(value)) | 260 | 393 | } |
Unexecuted instantiation: lebe::io::bytes::write_slice::<u32, std::io::cursor::Cursor<alloc::vec::Vec<u8>>> Unexecuted instantiation: lebe::io::bytes::write_slice::<u32, std::io::cursor::Cursor<&mut [u8]>> Unexecuted instantiation: lebe::io::bytes::write_slice::<u16, alloc::vec::Vec<u8>> Unexecuted instantiation: lebe::io::bytes::write_slice::<u16, std::io::cursor::Cursor<&mut [u8]>> lebe::io::bytes::write_slice::<u16, &mut [u8]> Line | Count | Source | 258 | 2.63M | pub unsafe fn write_slice<T>(write: &mut impl Write, value: &[T]) -> Result<()> { | 259 | 2.63M | write.write_all(slice_as_bytes(value)) | 260 | 2.63M | } |
Unexecuted instantiation: lebe::io::bytes::write_slice::<_, _> Unexecuted instantiation: lebe::io::bytes::write_slice::<i8, exr::io::Tracking<&mut &mut std::io::cursor::Cursor<alloc::vec::Vec<u8>>>> Unexecuted instantiation: lebe::io::bytes::write_slice::<f32, exr::io::Tracking<&mut &mut std::io::cursor::Cursor<alloc::vec::Vec<u8>>>> Unexecuted instantiation: lebe::io::bytes::write_slice::<u8, exr::io::Tracking<&mut &mut std::io::cursor::Cursor<alloc::vec::Vec<u8>>>> Unexecuted instantiation: lebe::io::bytes::write_slice::<u64, exr::io::Tracking<&mut &mut std::io::cursor::Cursor<alloc::vec::Vec<u8>>>> lebe::io::bytes::write_slice::<i8, exr::io::Tracking<&mut std::io::cursor::Cursor<&mut alloc::vec::Vec<u8>>>> Line | Count | Source | 258 | 312 | pub unsafe fn write_slice<T>(write: &mut impl Write, value: &[T]) -> Result<()> { | 259 | 312 | write.write_all(slice_as_bytes(value)) | 260 | 312 | } |
Unexecuted instantiation: lebe::io::bytes::write_slice::<f32, exr::io::Tracking<&mut std::io::cursor::Cursor<&mut alloc::vec::Vec<u8>>>> lebe::io::bytes::write_slice::<u8, exr::io::Tracking<&mut std::io::cursor::Cursor<&mut alloc::vec::Vec<u8>>>> Line | Count | Source | 258 | 725k | pub unsafe fn write_slice<T>(write: &mut impl Write, value: &[T]) -> Result<()> { | 259 | 725k | write.write_all(slice_as_bytes(value)) | 260 | 725k | } |
lebe::io::bytes::write_slice::<u64, exr::io::Tracking<&mut std::io::cursor::Cursor<&mut alloc::vec::Vec<u8>>>> Line | Count | Source | 258 | 78 | pub unsafe fn write_slice<T>(write: &mut impl Write, value: &[T]) -> Result<()> { | 259 | 78 | write.write_all(slice_as_bytes(value)) | 260 | 78 | } |
|
261 | | |
262 | | /// Read a slice of bytes into the specified slice. |
263 | | #[inline] |
264 | 69.5M | pub unsafe fn read_slice<T>(read: &mut impl Read, value: &mut [T]) -> Result<()> { |
265 | 69.5M | read.read_exact(slice_as_bytes_mut(value)) |
266 | 69.5M | } Unexecuted instantiation: lebe::io::bytes::read_slice::<i8, exr::io::PeekRead<exr::io::Tracking<std::io::cursor::Cursor<&[u8]>>>> lebe::io::bytes::read_slice::<i8, exr::io::PeekRead<&[u8]>> Line | Count | Source | 264 | 197k | pub unsafe fn read_slice<T>(read: &mut impl Read, value: &mut [T]) -> Result<()> { | 265 | 197k | read.read_exact(slice_as_bytes_mut(value)) | 266 | 197k | } |
lebe::io::bytes::read_slice::<i8, &[u8]> Line | Count | Source | 264 | 2.67k | pub unsafe fn read_slice<T>(read: &mut impl Read, value: &mut [T]) -> Result<()> { | 265 | 2.67k | read.read_exact(slice_as_bytes_mut(value)) | 266 | 2.67k | } |
lebe::io::bytes::read_slice::<f32, &mut &mut &[u8]> Line | Count | Source | 264 | 66.5M | pub unsafe fn read_slice<T>(read: &mut impl Read, value: &mut [T]) -> Result<()> { | 265 | 66.5M | read.read_exact(slice_as_bytes_mut(value)) | 266 | 66.5M | } |
lebe::io::bytes::read_slice::<f32, &[u8]> Line | Count | Source | 264 | 22.3k | pub unsafe fn read_slice<T>(read: &mut impl Read, value: &mut [T]) -> Result<()> { | 265 | 22.3k | read.read_exact(slice_as_bytes_mut(value)) | 266 | 22.3k | } |
lebe::io::bytes::read_slice::<u8, exr::io::PeekRead<exr::io::Tracking<std::io::cursor::Cursor<&[u8]>>>> Line | Count | Source | 264 | 1.75M | pub unsafe fn read_slice<T>(read: &mut impl Read, value: &mut [T]) -> Result<()> { | 265 | 1.75M | read.read_exact(slice_as_bytes_mut(value)) | 266 | 1.75M | } |
lebe::io::bytes::read_slice::<u8, exr::io::PeekRead<&[u8]>> Line | Count | Source | 264 | 1.60k | pub unsafe fn read_slice<T>(read: &mut impl Read, value: &mut [T]) -> Result<()> { | 265 | 1.60k | read.read_exact(slice_as_bytes_mut(value)) | 266 | 1.60k | } |
lebe::io::bytes::read_slice::<u32, &mut &mut &[u8]> Line | Count | Source | 264 | 64.9k | pub unsafe fn read_slice<T>(read: &mut impl Read, value: &mut [T]) -> Result<()> { | 265 | 64.9k | read.read_exact(slice_as_bytes_mut(value)) | 266 | 64.9k | } |
lebe::io::bytes::read_slice::<u16, &mut &mut &[u8]> Line | Count | Source | 264 | 127k | pub unsafe fn read_slice<T>(read: &mut impl Read, value: &mut [T]) -> Result<()> { | 265 | 127k | read.read_exact(slice_as_bytes_mut(value)) | 266 | 127k | } |
lebe::io::bytes::read_slice::<u64, exr::io::PeekRead<exr::io::Tracking<std::io::cursor::Cursor<&[u8]>>>> Line | Count | Source | 264 | 17.1k | pub unsafe fn read_slice<T>(read: &mut impl Read, value: &mut [T]) -> Result<()> { | 265 | 17.1k | read.read_exact(slice_as_bytes_mut(value)) | 266 | 17.1k | } |
Unexecuted instantiation: lebe::io::bytes::read_slice::<f32, std::io::cursor::Cursor<&[u8]>> lebe::io::bytes::read_slice::<u8, &[u8]> Line | Count | Source | 264 | 28.6k | pub unsafe fn read_slice<T>(read: &mut impl Read, value: &mut [T]) -> Result<()> { | 265 | 28.6k | read.read_exact(slice_as_bytes_mut(value)) | 266 | 28.6k | } |
Unexecuted instantiation: lebe::io::bytes::read_slice::<u32, std::io::cursor::Cursor<&[u8]>> Unexecuted instantiation: lebe::io::bytes::read_slice::<u16, std::io::cursor::Cursor<&[u8]>> Unexecuted instantiation: lebe::io::bytes::read_slice::<u16, &[u8]> Unexecuted instantiation: lebe::io::bytes::read_slice::<_, _> Unexecuted instantiation: lebe::io::bytes::read_slice::<i8, exr::io::PeekRead<exr::io::Tracking<std::io::cursor::Cursor<alloc::vec::Vec<u8>>>>> lebe::io::bytes::read_slice::<u8, exr::io::PeekRead<exr::io::Tracking<std::io::cursor::Cursor<alloc::vec::Vec<u8>>>>> Line | Count | Source | 264 | 723k | pub unsafe fn read_slice<T>(read: &mut impl Read, value: &mut [T]) -> Result<()> { | 265 | 723k | read.read_exact(slice_as_bytes_mut(value)) | 266 | 723k | } |
lebe::io::bytes::read_slice::<u64, exr::io::PeekRead<exr::io::Tracking<std::io::cursor::Cursor<alloc::vec::Vec<u8>>>>> Line | Count | Source | 264 | 81 | pub unsafe fn read_slice<T>(read: &mut impl Read, value: &mut [T]) -> Result<()> { | 265 | 81 | read.read_exact(slice_as_bytes_mut(value)) | 266 | 81 | } |
|
267 | | |
268 | | /// View this reference as a mutable slice of bytes and write it. |
269 | | #[inline] |
270 | 229M | pub unsafe fn write_value<T: Sized>(write: &mut impl Write, value: &T) -> Result<()> { |
271 | 229M | write.write_all(value_as_bytes(value)) |
272 | 229M | } Unexecuted instantiation: lebe::io::bytes::write_value::<i32, alloc::vec::Vec<u8>> Unexecuted instantiation: lebe::io::bytes::write_value::<u32, std::io::cursor::Cursor<alloc::vec::Vec<u8>>> lebe::io::bytes::write_value::<u16, alloc::vec::Vec<u8>> Line | Count | Source | 270 | 1.40M | pub unsafe fn write_value<T: Sized>(write: &mut impl Write, value: &T) -> Result<()> { | 271 | 1.40M | write.write_all(value_as_bytes(value)) | 272 | 1.40M | } |
Unexecuted instantiation: lebe::io::bytes::write_value::<u16, &mut [u8]> Unexecuted instantiation: lebe::io::bytes::write_value::<_, _> Unexecuted instantiation: lebe::io::bytes::write_value::<f64, exr::io::Tracking<&mut &mut std::io::cursor::Cursor<alloc::vec::Vec<u8>>>> Unexecuted instantiation: lebe::io::bytes::write_value::<f32, exr::io::Tracking<&mut &mut std::io::cursor::Cursor<alloc::vec::Vec<u8>>>> Unexecuted instantiation: lebe::io::bytes::write_value::<f32, &mut [u8]> Unexecuted instantiation: lebe::io::bytes::write_value::<u8, exr::io::Tracking<&mut &mut std::io::cursor::Cursor<alloc::vec::Vec<u8>>>> Unexecuted instantiation: lebe::io::bytes::write_value::<i32, exr::io::Tracking<&mut &mut std::io::cursor::Cursor<alloc::vec::Vec<u8>>>> Unexecuted instantiation: lebe::io::bytes::write_value::<u32, exr::io::Tracking<&mut &mut std::io::cursor::Cursor<alloc::vec::Vec<u8>>>> Unexecuted instantiation: lebe::io::bytes::write_value::<u32, &mut [u8]> Unexecuted instantiation: lebe::io::bytes::write_value::<u64, exr::io::Tracking<&mut &mut std::io::cursor::Cursor<alloc::vec::Vec<u8>>>> Unexecuted instantiation: lebe::io::bytes::write_value::<f64, exr::io::Tracking<&mut std::io::cursor::Cursor<&mut alloc::vec::Vec<u8>>>> lebe::io::bytes::write_value::<f32, exr::io::Tracking<&mut std::io::cursor::Cursor<&mut alloc::vec::Vec<u8>>>> Line | Count | Source | 270 | 312 | pub unsafe fn write_value<T: Sized>(write: &mut impl Write, value: &T) -> Result<()> { | 271 | 312 | write.write_all(value_as_bytes(value)) | 272 | 312 | } |
lebe::io::bytes::write_value::<f32, &mut [u8]> Line | Count | Source | 270 | 224M | pub unsafe fn write_value<T: Sized>(write: &mut impl Write, value: &T) -> Result<()> { | 271 | 224M | write.write_all(value_as_bytes(value)) | 272 | 224M | } |
lebe::io::bytes::write_value::<u8, exr::io::Tracking<&mut std::io::cursor::Cursor<&mut alloc::vec::Vec<u8>>>> Line | Count | Source | 270 | 2.73k | pub unsafe fn write_value<T: Sized>(write: &mut impl Write, value: &T) -> Result<()> { | 271 | 2.73k | write.write_all(value_as_bytes(value)) | 272 | 2.73k | } |
lebe::io::bytes::write_value::<i32, exr::io::Tracking<&mut std::io::cursor::Cursor<&mut alloc::vec::Vec<u8>>>> Line | Count | Source | 270 | 3.61M | pub unsafe fn write_value<T: Sized>(write: &mut impl Write, value: &T) -> Result<()> { | 271 | 3.61M | write.write_all(value_as_bytes(value)) | 272 | 3.61M | } |
lebe::io::bytes::write_value::<u32, exr::io::Tracking<&mut std::io::cursor::Cursor<&mut alloc::vec::Vec<u8>>>> Line | Count | Source | 270 | 234 | pub unsafe fn write_value<T: Sized>(write: &mut impl Write, value: &T) -> Result<()> { | 271 | 234 | write.write_all(value_as_bytes(value)) | 272 | 234 | } |
Unexecuted instantiation: lebe::io::bytes::write_value::<u32, &mut [u8]> Unexecuted instantiation: lebe::io::bytes::write_value::<u64, exr::io::Tracking<&mut std::io::cursor::Cursor<&mut alloc::vec::Vec<u8>>>> |
273 | | |
274 | | /// Read a slice of bytes into the specified reference. |
275 | | #[inline] |
276 | 56.1M | pub unsafe fn read_value<T: Sized>(read: &mut impl Read, value: &mut T) -> Result<()> { |
277 | 56.1M | read.read_exact(value_as_bytes_mut(value)) |
278 | 56.1M | } lebe::io::bytes::read_value::<f64, &[u8]> Line | Count | Source | 276 | 2.91k | pub unsafe fn read_value<T: Sized>(read: &mut impl Read, value: &mut T) -> Result<()> { | 277 | 2.91k | read.read_exact(value_as_bytes_mut(value)) | 278 | 2.91k | } |
lebe::io::bytes::read_value::<u8, exr::io::PeekRead<exr::io::Tracking<std::io::cursor::Cursor<&[u8]>>>> Line | Count | Source | 276 | 43.4M | pub unsafe fn read_value<T: Sized>(read: &mut impl Read, value: &mut T) -> Result<()> { | 277 | 43.4M | read.read_exact(value_as_bytes_mut(value)) | 278 | 43.4M | } |
lebe::io::bytes::read_value::<u8, exr::io::PeekRead<&[u8]>> Line | Count | Source | 276 | 1.43M | pub unsafe fn read_value<T: Sized>(read: &mut impl Read, value: &mut T) -> Result<()> { | 277 | 1.43M | read.read_exact(value_as_bytes_mut(value)) | 278 | 1.43M | } |
lebe::io::bytes::read_value::<u8, exr::io::Tracking<std::io::cursor::Cursor<&[u8]>>> Line | Count | Source | 276 | 1.87M | pub unsafe fn read_value<T: Sized>(read: &mut impl Read, value: &mut T) -> Result<()> { | 277 | 1.87M | read.read_exact(value_as_bytes_mut(value)) | 278 | 1.87M | } |
lebe::io::bytes::read_value::<i32, exr::io::PeekRead<exr::io::Tracking<std::io::cursor::Cursor<&[u8]>>>> Line | Count | Source | 276 | 1.86M | pub unsafe fn read_value<T: Sized>(read: &mut impl Read, value: &mut T) -> Result<()> { | 277 | 1.86M | read.read_exact(value_as_bytes_mut(value)) | 278 | 1.86M | } |
lebe::io::bytes::read_value::<i32, exr::io::PeekRead<&[u8]>> Line | Count | Source | 276 | 619k | pub unsafe fn read_value<T: Sized>(read: &mut impl Read, value: &mut T) -> Result<()> { | 277 | 619k | read.read_exact(value_as_bytes_mut(value)) | 278 | 619k | } |
lebe::io::bytes::read_value::<u32, exr::io::PeekRead<exr::io::Tracking<std::io::cursor::Cursor<&[u8]>>>> Line | Count | Source | 276 | 5.77k | pub unsafe fn read_value<T: Sized>(read: &mut impl Read, value: &mut T) -> Result<()> { | 277 | 5.77k | read.read_exact(value_as_bytes_mut(value)) | 278 | 5.77k | } |
Unexecuted instantiation: lebe::io::bytes::read_value::<u64, exr::io::PeekRead<exr::io::Tracking<std::io::cursor::Cursor<&[u8]>>>> lebe::io::bytes::read_value::<f32, &[u8]> Line | Count | Source | 276 | 342k | pub unsafe fn read_value<T: Sized>(read: &mut impl Read, value: &mut T) -> Result<()> { | 277 | 342k | read.read_exact(value_as_bytes_mut(value)) | 278 | 342k | } |
lebe::io::bytes::read_value::<u8, &[u8]> Line | Count | Source | 276 | 651k | pub unsafe fn read_value<T: Sized>(read: &mut impl Read, value: &mut T) -> Result<()> { | 277 | 651k | read.read_exact(value_as_bytes_mut(value)) | 278 | 651k | } |
lebe::io::bytes::read_value::<i32, &[u8]> Line | Count | Source | 276 | 747k | pub unsafe fn read_value<T: Sized>(read: &mut impl Read, value: &mut T) -> Result<()> { | 277 | 747k | read.read_exact(value_as_bytes_mut(value)) | 278 | 747k | } |
lebe::io::bytes::read_value::<u32, &[u8]> Line | Count | Source | 276 | 136k | pub unsafe fn read_value<T: Sized>(read: &mut impl Read, value: &mut T) -> Result<()> { | 277 | 136k | read.read_exact(value_as_bytes_mut(value)) | 278 | 136k | } |
lebe::io::bytes::read_value::<u16, &[u8]> Line | Count | Source | 276 | 1.40M | pub unsafe fn read_value<T: Sized>(read: &mut impl Read, value: &mut T) -> Result<()> { | 277 | 1.40M | read.read_exact(value_as_bytes_mut(value)) | 278 | 1.40M | } |
Unexecuted instantiation: lebe::io::bytes::read_value::<_, _> lebe::io::bytes::read_value::<u8, exr::io::PeekRead<exr::io::Tracking<std::io::cursor::Cursor<alloc::vec::Vec<u8>>>>> Line | Count | Source | 276 | 16.3k | pub unsafe fn read_value<T: Sized>(read: &mut impl Read, value: &mut T) -> Result<()> { | 277 | 16.3k | read.read_exact(value_as_bytes_mut(value)) | 278 | 16.3k | } |
lebe::io::bytes::read_value::<u8, exr::io::Tracking<std::io::cursor::Cursor<alloc::vec::Vec<u8>>>> Line | Count | Source | 276 | 936 | pub unsafe fn read_value<T: Sized>(read: &mut impl Read, value: &mut T) -> Result<()> { | 277 | 936 | read.read_exact(value_as_bytes_mut(value)) | 278 | 936 | } |
lebe::io::bytes::read_value::<i32, exr::io::PeekRead<exr::io::Tracking<std::io::cursor::Cursor<alloc::vec::Vec<u8>>>>> Line | Count | Source | 276 | 3.61M | pub unsafe fn read_value<T: Sized>(read: &mut impl Read, value: &mut T) -> Result<()> { | 277 | 3.61M | read.read_exact(value_as_bytes_mut(value)) | 278 | 3.61M | } |
lebe::io::bytes::read_value::<u32, exr::io::PeekRead<exr::io::Tracking<std::io::cursor::Cursor<alloc::vec::Vec<u8>>>>> Line | Count | Source | 276 | 78 | pub unsafe fn read_value<T: Sized>(read: &mut impl Read, value: &mut T) -> Result<()> { | 277 | 78 | read.read_exact(value_as_bytes_mut(value)) | 278 | 78 | } |
Unexecuted instantiation: lebe::io::bytes::read_value::<u64, exr::io::PeekRead<exr::io::Tracking<std::io::cursor::Cursor<alloc::vec::Vec<u8>>>>> |
279 | | } |
280 | | |
281 | | /// A `std::io::Write` output stream which supports writing any primitive values as bytes. |
282 | | /// Will encode the values to be either little endian or big endian, as desired. |
283 | | /// |
284 | | /// This extension trait is implemented for all `Write` types. |
285 | | /// Add `use lebe::io::WriteEndian;` to your code |
286 | | /// to automatically unlock this functionality for all types that implement `Write`. |
287 | | pub trait WriteEndian<T: ?Sized> { |
288 | | |
289 | | /// Write the byte value of the specified reference, converting it to little endianness |
290 | | fn write_as_little_endian(&mut self, value: &T) -> Result<()>; |
291 | | |
292 | | /// Write the byte value of the specified reference, converting it to big endianness |
293 | | fn write_as_big_endian(&mut self, value: &T) -> Result<()>; |
294 | | |
295 | | /// Write the byte value of the specified reference, not converting it |
296 | 228M | fn write_as_native_endian(&mut self, value: &T) -> Result<()> { |
297 | 228M | #[cfg(target_endian = "little")] { self.write_as_little_endian(value) } |
298 | | #[cfg(target_endian = "big")] { self.write_as_big_endian(value) } |
299 | 228M | } <alloc::vec::Vec<u8> as lebe::io::WriteEndian<[u8]>>::write_as_native_endian Line | Count | Source | 296 | 393 | fn write_as_native_endian(&mut self, value: &T) -> Result<()> { | 297 | 393 | #[cfg(target_endian = "little")] { self.write_as_little_endian(value) } | 298 | | #[cfg(target_endian = "big")] { self.write_as_big_endian(value) } | 299 | 393 | } |
<alloc::vec::Vec<u8> as lebe::io::WriteEndian<u16>>::write_as_native_endian Line | Count | Source | 296 | 1.40M | fn write_as_native_endian(&mut self, value: &T) -> Result<()> { | 297 | 1.40M | #[cfg(target_endian = "little")] { self.write_as_little_endian(value) } | 298 | | #[cfg(target_endian = "big")] { self.write_as_big_endian(value) } | 299 | 1.40M | } |
Unexecuted instantiation: <std::io::cursor::Cursor<&mut [u8]> as lebe::io::WriteEndian<[f32]>>::write_as_native_endian Unexecuted instantiation: <std::io::cursor::Cursor<&mut [u8]> as lebe::io::WriteEndian<[u32]>>::write_as_native_endian Unexecuted instantiation: <std::io::cursor::Cursor<&mut [u8]> as lebe::io::WriteEndian<[u16]>>::write_as_native_endian <&mut [u8] as lebe::io::WriteEndian<[u16]>>::write_as_native_endian Line | Count | Source | 296 | 2.63M | fn write_as_native_endian(&mut self, value: &T) -> Result<()> { | 297 | 2.63M | #[cfg(target_endian = "little")] { self.write_as_little_endian(value) } | 298 | | #[cfg(target_endian = "big")] { self.write_as_big_endian(value) } | 299 | 2.63M | } |
Unexecuted instantiation: <_ as lebe::io::WriteEndian<_>>::write_as_native_endian Unexecuted instantiation: <exr::io::Tracking<&mut &mut std::io::cursor::Cursor<alloc::vec::Vec<u8>>> as lebe::io::WriteEndian<[u8]>>::write_as_native_endian Unexecuted instantiation: <&mut [u8] as lebe::io::WriteEndian<f32>>::write_as_native_endian Unexecuted instantiation: <&mut [u8] as lebe::io::WriteEndian<u32>>::write_as_native_endian Unexecuted instantiation: <&mut [u8] as lebe::io::WriteEndian<u16>>::write_as_native_endian <&mut [u8] as lebe::io::WriteEndian<f32>>::write_as_native_endian Line | Count | Source | 296 | 224M | fn write_as_native_endian(&mut self, value: &T) -> Result<()> { | 297 | 224M | #[cfg(target_endian = "little")] { self.write_as_little_endian(value) } | 298 | | #[cfg(target_endian = "big")] { self.write_as_big_endian(value) } | 299 | 224M | } |
Unexecuted instantiation: <&mut [u8] as lebe::io::WriteEndian<u32>>::write_as_native_endian Unexecuted instantiation: <&mut [u8] as lebe::io::WriteEndian<u16>>::write_as_native_endian <exr::io::Tracking<&mut std::io::cursor::Cursor<&mut alloc::vec::Vec<u8>>> as lebe::io::WriteEndian<[u8]>>::write_as_native_endian Line | Count | Source | 296 | 78 | fn write_as_native_endian(&mut self, value: &T) -> Result<()> { | 297 | 78 | #[cfg(target_endian = "little")] { self.write_as_little_endian(value) } | 298 | | #[cfg(target_endian = "big")] { self.write_as_big_endian(value) } | 299 | 78 | } |
|
300 | | } |
301 | | |
302 | | /// A `std::io::Read` input stream which supports reading any primitive values from bytes. |
303 | | /// Will decode the values from either little endian or big endian, as desired. |
304 | | /// |
305 | | /// This extension trait is implemented for all `Read` types. |
306 | | /// Add `use lebe::io::ReadEndian;` to your code |
307 | | /// to automatically unlock this functionality for all types that implement `Read`. |
308 | | pub trait ReadEndian<T: ?Sized> { |
309 | | |
310 | | /// Read into the supplied reference. Acts the same as `std::io::Read::read_exact`. |
311 | | fn read_from_little_endian_into(&mut self, value: &mut T) -> Result<()>; |
312 | | |
313 | | /// Read into the supplied reference. Acts the same as `std::io::Read::read_exact`. |
314 | | fn read_from_big_endian_into(&mut self, value: &mut T) -> Result<()>; |
315 | | |
316 | | /// Read into the supplied reference. Acts the same as `std::io::Read::read_exact`. |
317 | 66.7M | fn read_from_native_endian_into(&mut self, value: &mut T) -> Result<()> { |
318 | 66.7M | #[cfg(target_endian = "little")] { self.read_from_little_endian_into(value) } |
319 | | #[cfg(target_endian = "big")] { self.read_from_big_endian_into(value) } |
320 | 66.7M | } <exr::io::PeekRead<exr::io::Tracking<std::io::cursor::Cursor<&[u8]>>> as lebe::io::ReadEndian<[u8]>>::read_from_native_endian_into Line | Count | Source | 317 | 5.77k | fn read_from_native_endian_into(&mut self, value: &mut T) -> Result<()> { | 318 | 5.77k | #[cfg(target_endian = "little")] { self.read_from_little_endian_into(value) } | 319 | | #[cfg(target_endian = "big")] { self.read_from_big_endian_into(value) } | 320 | 5.77k | } |
<&mut &mut &[u8] as lebe::io::ReadEndian<[f32]>>::read_from_native_endian_into Line | Count | Source | 317 | 66.5M | fn read_from_native_endian_into(&mut self, value: &mut T) -> Result<()> { | 318 | 66.5M | #[cfg(target_endian = "little")] { self.read_from_little_endian_into(value) } | 319 | | #[cfg(target_endian = "big")] { self.read_from_big_endian_into(value) } | 320 | 66.5M | } |
<&mut &mut &[u8] as lebe::io::ReadEndian<[u32]>>::read_from_native_endian_into Line | Count | Source | 317 | 64.9k | fn read_from_native_endian_into(&mut self, value: &mut T) -> Result<()> { | 318 | 64.9k | #[cfg(target_endian = "little")] { self.read_from_little_endian_into(value) } | 319 | | #[cfg(target_endian = "big")] { self.read_from_big_endian_into(value) } | 320 | 64.9k | } |
<&mut &mut &[u8] as lebe::io::ReadEndian<[u16]>>::read_from_native_endian_into Line | Count | Source | 317 | 127k | fn read_from_native_endian_into(&mut self, value: &mut T) -> Result<()> { | 318 | 127k | #[cfg(target_endian = "little")] { self.read_from_little_endian_into(value) } | 319 | | #[cfg(target_endian = "big")] { self.read_from_big_endian_into(value) } | 320 | 127k | } |
Unexecuted instantiation: <std::io::cursor::Cursor<&[u8]> as lebe::io::ReadEndian<[f32]>>::read_from_native_endian_into Unexecuted instantiation: <std::io::cursor::Cursor<&[u8]> as lebe::io::ReadEndian<[u32]>>::read_from_native_endian_into Unexecuted instantiation: <std::io::cursor::Cursor<&[u8]> as lebe::io::ReadEndian<[u16]>>::read_from_native_endian_into <&[u8] as lebe::io::ReadEndian<[u8]>>::read_from_native_endian_into Line | Count | Source | 317 | 140 | fn read_from_native_endian_into(&mut self, value: &mut T) -> Result<()> { | 318 | 140 | #[cfg(target_endian = "little")] { self.read_from_little_endian_into(value) } | 319 | | #[cfg(target_endian = "big")] { self.read_from_big_endian_into(value) } | 320 | 140 | } |
Unexecuted instantiation: <&[u8] as lebe::io::ReadEndian<[u16]>>::read_from_native_endian_into Unexecuted instantiation: <_ as lebe::io::ReadEndian<_>>::read_from_native_endian_into <exr::io::PeekRead<exr::io::Tracking<std::io::cursor::Cursor<alloc::vec::Vec<u8>>>> as lebe::io::ReadEndian<[u8]>>::read_from_native_endian_into Line | Count | Source | 317 | 78 | fn read_from_native_endian_into(&mut self, value: &mut T) -> Result<()> { | 318 | 78 | #[cfg(target_endian = "little")] { self.read_from_little_endian_into(value) } | 319 | | #[cfg(target_endian = "big")] { self.read_from_big_endian_into(value) } | 320 | 78 | } |
|
321 | | |
322 | | /// Read the byte value of the inferred type |
323 | | #[inline] |
324 | 56.1M | fn read_from_little_endian(&mut self) -> Result<T> where T: Sized + Default { |
325 | 56.1M | let mut value = T::default(); |
326 | 56.1M | self.read_from_little_endian_into(&mut value)?; |
327 | 56.1M | Ok(value) |
328 | 56.1M | } <exr::io::PeekRead<exr::io::Tracking<std::io::cursor::Cursor<&[u8]>>> as lebe::io::ReadEndian<u8>>::read_from_little_endian Line | Count | Source | 324 | 43.4M | fn read_from_little_endian(&mut self) -> Result<T> where T: Sized + Default { | 325 | 43.4M | let mut value = T::default(); | 326 | 43.4M | self.read_from_little_endian_into(&mut value)?; | 327 | 43.4M | Ok(value) | 328 | 43.4M | } |
<exr::io::PeekRead<exr::io::Tracking<std::io::cursor::Cursor<&[u8]>>> as lebe::io::ReadEndian<i32>>::read_from_little_endian Line | Count | Source | 324 | 1.86M | fn read_from_little_endian(&mut self) -> Result<T> where T: Sized + Default { | 325 | 1.86M | let mut value = T::default(); | 326 | 1.86M | self.read_from_little_endian_into(&mut value)?; | 327 | 1.86M | Ok(value) | 328 | 1.86M | } |
<exr::io::PeekRead<exr::io::Tracking<std::io::cursor::Cursor<&[u8]>>> as lebe::io::ReadEndian<u32>>::read_from_little_endian Line | Count | Source | 324 | 5.77k | fn read_from_little_endian(&mut self) -> Result<T> where T: Sized + Default { | 325 | 5.77k | let mut value = T::default(); | 326 | 5.77k | self.read_from_little_endian_into(&mut value)?; | 327 | 5.77k | Ok(value) | 328 | 5.77k | } |
Unexecuted instantiation: <exr::io::PeekRead<exr::io::Tracking<std::io::cursor::Cursor<&[u8]>>> as lebe::io::ReadEndian<u64>>::read_from_little_endian <exr::io::PeekRead<&[u8]> as lebe::io::ReadEndian<u8>>::read_from_little_endian Line | Count | Source | 324 | 1.43M | fn read_from_little_endian(&mut self) -> Result<T> where T: Sized + Default { | 325 | 1.43M | let mut value = T::default(); | 326 | 1.43M | self.read_from_little_endian_into(&mut value)?; | 327 | 1.43M | Ok(value) | 328 | 1.43M | } |
<exr::io::PeekRead<&[u8]> as lebe::io::ReadEndian<i32>>::read_from_little_endian Line | Count | Source | 324 | 619k | fn read_from_little_endian(&mut self) -> Result<T> where T: Sized + Default { | 325 | 619k | let mut value = T::default(); | 326 | 619k | self.read_from_little_endian_into(&mut value)?; | 327 | 619k | Ok(value) | 328 | 619k | } |
<exr::io::Tracking<std::io::cursor::Cursor<&[u8]>> as lebe::io::ReadEndian<u8>>::read_from_little_endian Line | Count | Source | 324 | 1.87M | fn read_from_little_endian(&mut self) -> Result<T> where T: Sized + Default { | 325 | 1.87M | let mut value = T::default(); | 326 | 1.87M | self.read_from_little_endian_into(&mut value)?; | 327 | 1.87M | Ok(value) | 328 | 1.87M | } |
<&[u8] as lebe::io::ReadEndian<f64>>::read_from_little_endian Line | Count | Source | 324 | 2.91k | fn read_from_little_endian(&mut self) -> Result<T> where T: Sized + Default { | 325 | 2.91k | let mut value = T::default(); | 326 | 2.91k | self.read_from_little_endian_into(&mut value)?; | 327 | 2.91k | Ok(value) | 328 | 2.91k | } |
<&[u8] as lebe::io::ReadEndian<f32>>::read_from_little_endian Line | Count | Source | 324 | 342k | fn read_from_little_endian(&mut self) -> Result<T> where T: Sized + Default { | 325 | 342k | let mut value = T::default(); | 326 | 342k | self.read_from_little_endian_into(&mut value)?; | 327 | 342k | Ok(value) | 328 | 342k | } |
<&[u8] as lebe::io::ReadEndian<u8>>::read_from_little_endian Line | Count | Source | 324 | 651k | fn read_from_little_endian(&mut self) -> Result<T> where T: Sized + Default { | 325 | 651k | let mut value = T::default(); | 326 | 651k | self.read_from_little_endian_into(&mut value)?; | 327 | 651k | Ok(value) | 328 | 651k | } |
<&[u8] as lebe::io::ReadEndian<i32>>::read_from_little_endian Line | Count | Source | 324 | 747k | fn read_from_little_endian(&mut self) -> Result<T> where T: Sized + Default { | 325 | 747k | let mut value = T::default(); | 326 | 747k | self.read_from_little_endian_into(&mut value)?; | 327 | 747k | Ok(value) | 328 | 747k | } |
<&[u8] as lebe::io::ReadEndian<u32>>::read_from_little_endian Line | Count | Source | 324 | 136k | fn read_from_little_endian(&mut self) -> Result<T> where T: Sized + Default { | 325 | 136k | let mut value = T::default(); | 326 | 136k | self.read_from_little_endian_into(&mut value)?; | 327 | 136k | Ok(value) | 328 | 136k | } |
<&[u8] as lebe::io::ReadEndian<u16>>::read_from_little_endian Line | Count | Source | 324 | 1.40M | fn read_from_little_endian(&mut self) -> Result<T> where T: Sized + Default { | 325 | 1.40M | let mut value = T::default(); | 326 | 1.40M | self.read_from_little_endian_into(&mut value)?; | 327 | 1.40M | Ok(value) | 328 | 1.40M | } |
Unexecuted instantiation: <_ as lebe::io::ReadEndian<_>>::read_from_little_endian <exr::io::PeekRead<exr::io::Tracking<std::io::cursor::Cursor<alloc::vec::Vec<u8>>>> as lebe::io::ReadEndian<u8>>::read_from_little_endian Line | Count | Source | 324 | 16.3k | fn read_from_little_endian(&mut self) -> Result<T> where T: Sized + Default { | 325 | 16.3k | let mut value = T::default(); | 326 | 16.3k | self.read_from_little_endian_into(&mut value)?; | 327 | 16.3k | Ok(value) | 328 | 16.3k | } |
<exr::io::PeekRead<exr::io::Tracking<std::io::cursor::Cursor<alloc::vec::Vec<u8>>>> as lebe::io::ReadEndian<i32>>::read_from_little_endian Line | Count | Source | 324 | 3.61M | fn read_from_little_endian(&mut self) -> Result<T> where T: Sized + Default { | 325 | 3.61M | let mut value = T::default(); | 326 | 3.61M | self.read_from_little_endian_into(&mut value)?; | 327 | 3.61M | Ok(value) | 328 | 3.61M | } |
<exr::io::PeekRead<exr::io::Tracking<std::io::cursor::Cursor<alloc::vec::Vec<u8>>>> as lebe::io::ReadEndian<u32>>::read_from_little_endian Line | Count | Source | 324 | 78 | fn read_from_little_endian(&mut self) -> Result<T> where T: Sized + Default { | 325 | 78 | let mut value = T::default(); | 326 | 78 | self.read_from_little_endian_into(&mut value)?; | 327 | 78 | Ok(value) | 328 | 78 | } |
Unexecuted instantiation: <exr::io::PeekRead<exr::io::Tracking<std::io::cursor::Cursor<alloc::vec::Vec<u8>>>> as lebe::io::ReadEndian<u64>>::read_from_little_endian <exr::io::Tracking<std::io::cursor::Cursor<alloc::vec::Vec<u8>>> as lebe::io::ReadEndian<u8>>::read_from_little_endian Line | Count | Source | 324 | 936 | fn read_from_little_endian(&mut self) -> Result<T> where T: Sized + Default { | 325 | 936 | let mut value = T::default(); | 326 | 936 | self.read_from_little_endian_into(&mut value)?; | 327 | 936 | Ok(value) | 328 | 936 | } |
|
329 | | |
330 | | /// Read the byte value of the inferred type |
331 | | #[inline] |
332 | 0 | fn read_from_big_endian(&mut self) -> Result<T> where T: Sized + Default { |
333 | 0 | let mut value = T::default(); |
334 | 0 | self.read_from_big_endian_into(&mut value)?; |
335 | 0 | Ok(value) |
336 | 0 | } |
337 | | |
338 | | /// Read the byte value of the inferred type |
339 | | #[inline] |
340 | 271k | fn read_from_native_endian(&mut self) -> Result<T> where T: Sized + Default { |
341 | 271k | #[cfg(target_endian = "little")] { self.read_from_little_endian() } |
342 | | #[cfg(target_endian = "big")] { self.read_from_big_endian() } |
343 | 271k | } Unexecuted instantiation: <&[u8] as lebe::io::ReadEndian<f32>>::read_from_native_endian <&[u8] as lebe::io::ReadEndian<u8>>::read_from_native_endian Line | Count | Source | 340 | 271k | fn read_from_native_endian(&mut self) -> Result<T> where T: Sized + Default { | 341 | 271k | #[cfg(target_endian = "little")] { self.read_from_little_endian() } | 342 | | #[cfg(target_endian = "big")] { self.read_from_big_endian() } | 343 | 271k | } |
Unexecuted instantiation: <&[u8] as lebe::io::ReadEndian<u32>>::read_from_native_endian Unexecuted instantiation: <&[u8] as lebe::io::ReadEndian<u16>>::read_from_native_endian Unexecuted instantiation: <_ as lebe::io::ReadEndian<_>>::read_from_native_endian |
344 | | } |
345 | | |
346 | | // implement primitive for all types that are implemented by `Read` |
347 | | impl<R: Read + ReadEndian<P>, P: Default> ReadPrimitive<R> for P {} |
348 | | |
349 | | |
350 | | /// Offers a prettier versions of reading a primitive number. |
351 | | /// |
352 | | /// The default way of reading a value is: |
353 | | /// ```rust |
354 | | /// # use std::io::Read; |
355 | | /// # use lebe::prelude::*; |
356 | | /// # let mut reader : &[u8] = &[2, 1]; |
357 | | /// |
358 | | /// let number: u16 = reader.read_from_little_endian()?; |
359 | | /// println!("{}", number); |
360 | | /// # Ok::<(), std::io::Error>(()) |
361 | | /// |
362 | | /// ``` |
363 | | /// |
364 | | /// This trait enables you to use expressions: |
365 | | /// ```rust |
366 | | /// # use std::io::Read; |
367 | | /// # use lebe::prelude::*; |
368 | | /// # let mut reader : &[u8] = &[2, 1]; |
369 | | /// |
370 | | /// println!("{}", u16::read_from_little_endian(&mut reader)?); |
371 | | /// # Ok::<(), std::io::Error>(()) |
372 | | /// ``` |
373 | | /// . |
374 | | /// |
375 | | pub trait ReadPrimitive<R: Read + ReadEndian<Self>> : Sized + Default { |
376 | | /// Read this value from the supplied reader. Same as `ReadEndian::read_from_little_endian()`. |
377 | 3.55M | fn read_from_little_endian(read: &mut R) -> Result<Self> { |
378 | 3.55M | read.read_from_little_endian() |
379 | 3.55M | } <u8 as lebe::io::ReadPrimitive<exr::io::Tracking<std::io::cursor::Cursor<&[u8]>>>>::read_from_little_endian Line | Count | Source | 377 | 1.87M | fn read_from_little_endian(read: &mut R) -> Result<Self> { | 378 | 1.87M | read.read_from_little_endian() | 379 | 1.87M | } |
<u8 as lebe::io::ReadPrimitive<&[u8]>>::read_from_little_endian Line | Count | Source | 377 | 279k | fn read_from_little_endian(read: &mut R) -> Result<Self> { | 378 | 279k | read.read_from_little_endian() | 379 | 279k | } |
<u16 as lebe::io::ReadPrimitive<&[u8]>>::read_from_little_endian Line | Count | Source | 377 | 1.40M | fn read_from_little_endian(read: &mut R) -> Result<Self> { | 378 | 1.40M | read.read_from_little_endian() | 379 | 1.40M | } |
Unexecuted instantiation: <_ as lebe::io::ReadPrimitive<_>>::read_from_little_endian <u8 as lebe::io::ReadPrimitive<exr::io::Tracking<std::io::cursor::Cursor<alloc::vec::Vec<u8>>>>>::read_from_little_endian Line | Count | Source | 377 | 936 | fn read_from_little_endian(read: &mut R) -> Result<Self> { | 378 | 936 | read.read_from_little_endian() | 379 | 936 | } |
|
380 | | |
381 | | /// Read this value from the supplied reader. Same as `ReadEndian::read_from_big_endian()`. |
382 | 0 | fn read_from_big_endian(read: &mut R) -> Result<Self> { |
383 | 0 | read.read_from_big_endian() |
384 | 0 | } |
385 | | |
386 | | /// Read this value from the supplied reader. Same as `ReadEndian::read_from_native_endian()`. |
387 | 0 | fn read_from_native_endian(read: &mut R) -> Result<Self> { |
388 | 0 | read.read_from_native_endian() |
389 | 0 | } Unexecuted instantiation: <f32 as lebe::io::ReadPrimitive<&[u8]>>::read_from_native_endian Unexecuted instantiation: <u32 as lebe::io::ReadPrimitive<&[u8]>>::read_from_native_endian Unexecuted instantiation: <u16 as lebe::io::ReadPrimitive<&[u8]>>::read_from_native_endian Unexecuted instantiation: <_ as lebe::io::ReadPrimitive<_>>::read_from_native_endian |
390 | | } |
391 | | |
392 | | macro_rules! implement_simple_primitive_write { |
393 | | ($type: ident) => { |
394 | | impl<W: Write> WriteEndian<$type> for W { |
395 | 229M | fn write_as_little_endian(&mut self, value: &$type) -> Result<()> { |
396 | 229M | unsafe { bytes::write_value(self, &value.from_current_into_little_endian()) } |
397 | 229M | } <alloc::vec::Vec<u8> as lebe::io::WriteEndian<u16>>::write_as_little_endian Line | Count | Source | 395 | 1.40M | fn write_as_little_endian(&mut self, value: &$type) -> Result<()> { | 396 | 1.40M | unsafe { bytes::write_value(self, &value.from_current_into_little_endian()) } | 397 | 1.40M | } |
Unexecuted instantiation: <alloc::vec::Vec<u8> as lebe::io::WriteEndian<i32>>::write_as_little_endian Unexecuted instantiation: <std::io::cursor::Cursor<alloc::vec::Vec<u8>> as lebe::io::WriteEndian<u32>>::write_as_little_endian Unexecuted instantiation: <&mut [u8] as lebe::io::WriteEndian<u16>>::write_as_little_endian Unexecuted instantiation: <_ as lebe::io::WriteEndian<u16>>::write_as_little_endian Unexecuted instantiation: <_ as lebe::io::WriteEndian<u32>>::write_as_little_endian Unexecuted instantiation: <_ as lebe::io::WriteEndian<u64>>::write_as_little_endian Unexecuted instantiation: <_ as lebe::io::WriteEndian<u128>>::write_as_little_endian Unexecuted instantiation: <_ as lebe::io::WriteEndian<i8>>::write_as_little_endian Unexecuted instantiation: <_ as lebe::io::WriteEndian<u8>>::write_as_little_endian Unexecuted instantiation: <_ as lebe::io::WriteEndian<i16>>::write_as_little_endian Unexecuted instantiation: <_ as lebe::io::WriteEndian<i32>>::write_as_little_endian Unexecuted instantiation: <_ as lebe::io::WriteEndian<i64>>::write_as_little_endian Unexecuted instantiation: <_ as lebe::io::WriteEndian<i128>>::write_as_little_endian Unexecuted instantiation: <_ as lebe::io::WriteEndian<f32>>::write_as_little_endian Unexecuted instantiation: <_ as lebe::io::WriteEndian<f64>>::write_as_little_endian Unexecuted instantiation: <exr::io::Tracking<&mut &mut std::io::cursor::Cursor<alloc::vec::Vec<u8>>> as lebe::io::WriteEndian<u32>>::write_as_little_endian Unexecuted instantiation: <exr::io::Tracking<&mut &mut std::io::cursor::Cursor<alloc::vec::Vec<u8>>> as lebe::io::WriteEndian<u64>>::write_as_little_endian Unexecuted instantiation: <exr::io::Tracking<&mut &mut std::io::cursor::Cursor<alloc::vec::Vec<u8>>> as lebe::io::WriteEndian<u8>>::write_as_little_endian Unexecuted instantiation: <exr::io::Tracking<&mut &mut std::io::cursor::Cursor<alloc::vec::Vec<u8>>> as lebe::io::WriteEndian<i32>>::write_as_little_endian Unexecuted instantiation: <exr::io::Tracking<&mut &mut std::io::cursor::Cursor<alloc::vec::Vec<u8>>> as lebe::io::WriteEndian<f32>>::write_as_little_endian Unexecuted instantiation: <exr::io::Tracking<&mut &mut std::io::cursor::Cursor<alloc::vec::Vec<u8>>> as lebe::io::WriteEndian<f64>>::write_as_little_endian Unexecuted instantiation: <&mut [u8] as lebe::io::WriteEndian<u32>>::write_as_little_endian Unexecuted instantiation: <&mut [u8] as lebe::io::WriteEndian<f32>>::write_as_little_endian Unexecuted instantiation: <&mut [u8] as lebe::io::WriteEndian<u32>>::write_as_little_endian <&mut [u8] as lebe::io::WriteEndian<f32>>::write_as_little_endian Line | Count | Source | 395 | 224M | fn write_as_little_endian(&mut self, value: &$type) -> Result<()> { | 396 | 224M | unsafe { bytes::write_value(self, &value.from_current_into_little_endian()) } | 397 | 224M | } |
<exr::io::Tracking<&mut std::io::cursor::Cursor<&mut alloc::vec::Vec<u8>>> as lebe::io::WriteEndian<u32>>::write_as_little_endian Line | Count | Source | 395 | 234 | fn write_as_little_endian(&mut self, value: &$type) -> Result<()> { | 396 | 234 | unsafe { bytes::write_value(self, &value.from_current_into_little_endian()) } | 397 | 234 | } |
Unexecuted instantiation: <exr::io::Tracking<&mut std::io::cursor::Cursor<&mut alloc::vec::Vec<u8>>> as lebe::io::WriteEndian<u64>>::write_as_little_endian <exr::io::Tracking<&mut std::io::cursor::Cursor<&mut alloc::vec::Vec<u8>>> as lebe::io::WriteEndian<u8>>::write_as_little_endian Line | Count | Source | 395 | 2.73k | fn write_as_little_endian(&mut self, value: &$type) -> Result<()> { | 396 | 2.73k | unsafe { bytes::write_value(self, &value.from_current_into_little_endian()) } | 397 | 2.73k | } |
<exr::io::Tracking<&mut std::io::cursor::Cursor<&mut alloc::vec::Vec<u8>>> as lebe::io::WriteEndian<i32>>::write_as_little_endian Line | Count | Source | 395 | 3.61M | fn write_as_little_endian(&mut self, value: &$type) -> Result<()> { | 396 | 3.61M | unsafe { bytes::write_value(self, &value.from_current_into_little_endian()) } | 397 | 3.61M | } |
<exr::io::Tracking<&mut std::io::cursor::Cursor<&mut alloc::vec::Vec<u8>>> as lebe::io::WriteEndian<f32>>::write_as_little_endian Line | Count | Source | 395 | 312 | fn write_as_little_endian(&mut self, value: &$type) -> Result<()> { | 396 | 312 | unsafe { bytes::write_value(self, &value.from_current_into_little_endian()) } | 397 | 312 | } |
Unexecuted instantiation: <exr::io::Tracking<&mut std::io::cursor::Cursor<&mut alloc::vec::Vec<u8>>> as lebe::io::WriteEndian<f64>>::write_as_little_endian |
398 | | |
399 | 0 | fn write_as_big_endian(&mut self, value: &$type) -> Result<()> { |
400 | 0 | unsafe { bytes::write_value(self, &value.from_current_into_big_endian()) } |
401 | 0 | } Unexecuted instantiation: <_ as lebe::io::WriteEndian<u16>>::write_as_big_endian Unexecuted instantiation: <_ as lebe::io::WriteEndian<u32>>::write_as_big_endian Unexecuted instantiation: <_ as lebe::io::WriteEndian<u64>>::write_as_big_endian Unexecuted instantiation: <_ as lebe::io::WriteEndian<u128>>::write_as_big_endian Unexecuted instantiation: <_ as lebe::io::WriteEndian<i8>>::write_as_big_endian Unexecuted instantiation: <_ as lebe::io::WriteEndian<u8>>::write_as_big_endian Unexecuted instantiation: <_ as lebe::io::WriteEndian<i16>>::write_as_big_endian Unexecuted instantiation: <_ as lebe::io::WriteEndian<i32>>::write_as_big_endian Unexecuted instantiation: <_ as lebe::io::WriteEndian<i64>>::write_as_big_endian Unexecuted instantiation: <_ as lebe::io::WriteEndian<i128>>::write_as_big_endian Unexecuted instantiation: <_ as lebe::io::WriteEndian<f32>>::write_as_big_endian Unexecuted instantiation: <_ as lebe::io::WriteEndian<f64>>::write_as_big_endian |
402 | | } |
403 | | |
404 | | impl<R: Read> ReadEndian<$type> for R { |
405 | | #[inline] |
406 | 56.1M | fn read_from_little_endian_into(&mut self, value: &mut $type) -> Result<()> { |
407 | 56.1M | unsafe { bytes::read_value(self, value)?; } |
408 | 56.1M | value.convert_little_endian_to_current(); |
409 | 56.1M | Ok(()) |
410 | 56.1M | } <exr::io::PeekRead<exr::io::Tracking<std::io::cursor::Cursor<&[u8]>>> as lebe::io::ReadEndian<u8>>::read_from_little_endian_into Line | Count | Source | 406 | 43.4M | fn read_from_little_endian_into(&mut self, value: &mut $type) -> Result<()> { | 407 | 43.4M | unsafe { bytes::read_value(self, value)?; } | 408 | 43.4M | value.convert_little_endian_to_current(); | 409 | 43.4M | Ok(()) | 410 | 43.4M | } |
<exr::io::PeekRead<&[u8]> as lebe::io::ReadEndian<u8>>::read_from_little_endian_into Line | Count | Source | 406 | 1.43M | fn read_from_little_endian_into(&mut self, value: &mut $type) -> Result<()> { | 407 | 1.43M | unsafe { bytes::read_value(self, value)?; } | 408 | 1.43M | value.convert_little_endian_to_current(); | 409 | 1.43M | Ok(()) | 410 | 1.43M | } |
<exr::io::Tracking<std::io::cursor::Cursor<&[u8]>> as lebe::io::ReadEndian<u8>>::read_from_little_endian_into Line | Count | Source | 406 | 1.87M | fn read_from_little_endian_into(&mut self, value: &mut $type) -> Result<()> { | 407 | 1.87M | unsafe { bytes::read_value(self, value)?; } | 408 | 1.87M | value.convert_little_endian_to_current(); | 409 | 1.87M | Ok(()) | 410 | 1.87M | } |
<exr::io::PeekRead<exr::io::Tracking<std::io::cursor::Cursor<&[u8]>>> as lebe::io::ReadEndian<u32>>::read_from_little_endian_into Line | Count | Source | 406 | 5.77k | fn read_from_little_endian_into(&mut self, value: &mut $type) -> Result<()> { | 407 | 5.77k | unsafe { bytes::read_value(self, value)?; } | 408 | 5.77k | value.convert_little_endian_to_current(); | 409 | 5.77k | Ok(()) | 410 | 5.77k | } |
Unexecuted instantiation: <exr::io::PeekRead<exr::io::Tracking<std::io::cursor::Cursor<&[u8]>>> as lebe::io::ReadEndian<u64>>::read_from_little_endian_into <exr::io::PeekRead<exr::io::Tracking<std::io::cursor::Cursor<&[u8]>>> as lebe::io::ReadEndian<i32>>::read_from_little_endian_into Line | Count | Source | 406 | 1.86M | fn read_from_little_endian_into(&mut self, value: &mut $type) -> Result<()> { | 407 | 1.86M | unsafe { bytes::read_value(self, value)?; } | 408 | 1.86M | value.convert_little_endian_to_current(); | 409 | 1.86M | Ok(()) | 410 | 1.86M | } |
<exr::io::PeekRead<&[u8]> as lebe::io::ReadEndian<i32>>::read_from_little_endian_into Line | Count | Source | 406 | 619k | fn read_from_little_endian_into(&mut self, value: &mut $type) -> Result<()> { | 407 | 619k | unsafe { bytes::read_value(self, value)?; } | 408 | 619k | value.convert_little_endian_to_current(); | 409 | 619k | Ok(()) | 410 | 619k | } |
<&[u8] as lebe::io::ReadEndian<f64>>::read_from_little_endian_into Line | Count | Source | 406 | 2.91k | fn read_from_little_endian_into(&mut self, value: &mut $type) -> Result<()> { | 407 | 2.91k | unsafe { bytes::read_value(self, value)?; } | 408 | 2.91k | value.convert_little_endian_to_current(); | 409 | 2.91k | Ok(()) | 410 | 2.91k | } |
<&[u8] as lebe::io::ReadEndian<u8>>::read_from_little_endian_into Line | Count | Source | 406 | 651k | fn read_from_little_endian_into(&mut self, value: &mut $type) -> Result<()> { | 407 | 651k | unsafe { bytes::read_value(self, value)?; } | 408 | 651k | value.convert_little_endian_to_current(); | 409 | 651k | Ok(()) | 410 | 651k | } |
<&[u8] as lebe::io::ReadEndian<u16>>::read_from_little_endian_into Line | Count | Source | 406 | 1.40M | fn read_from_little_endian_into(&mut self, value: &mut $type) -> Result<()> { | 407 | 1.40M | unsafe { bytes::read_value(self, value)?; } | 408 | 1.40M | value.convert_little_endian_to_current(); | 409 | 1.40M | Ok(()) | 410 | 1.40M | } |
<&[u8] as lebe::io::ReadEndian<u32>>::read_from_little_endian_into Line | Count | Source | 406 | 136k | fn read_from_little_endian_into(&mut self, value: &mut $type) -> Result<()> { | 407 | 136k | unsafe { bytes::read_value(self, value)?; } | 408 | 136k | value.convert_little_endian_to_current(); | 409 | 136k | Ok(()) | 410 | 136k | } |
<&[u8] as lebe::io::ReadEndian<i32>>::read_from_little_endian_into Line | Count | Source | 406 | 747k | fn read_from_little_endian_into(&mut self, value: &mut $type) -> Result<()> { | 407 | 747k | unsafe { bytes::read_value(self, value)?; } | 408 | 747k | value.convert_little_endian_to_current(); | 409 | 747k | Ok(()) | 410 | 747k | } |
<&[u8] as lebe::io::ReadEndian<f32>>::read_from_little_endian_into Line | Count | Source | 406 | 342k | fn read_from_little_endian_into(&mut self, value: &mut $type) -> Result<()> { | 407 | 342k | unsafe { bytes::read_value(self, value)?; } | 408 | 342k | value.convert_little_endian_to_current(); | 409 | 342k | Ok(()) | 410 | 342k | } |
Unexecuted instantiation: <_ as lebe::io::ReadEndian<u8>>::read_from_little_endian_into Unexecuted instantiation: <_ as lebe::io::ReadEndian<u16>>::read_from_little_endian_into Unexecuted instantiation: <_ as lebe::io::ReadEndian<u32>>::read_from_little_endian_into Unexecuted instantiation: <_ as lebe::io::ReadEndian<u64>>::read_from_little_endian_into Unexecuted instantiation: <_ as lebe::io::ReadEndian<u128>>::read_from_little_endian_into Unexecuted instantiation: <_ as lebe::io::ReadEndian<i8>>::read_from_little_endian_into Unexecuted instantiation: <_ as lebe::io::ReadEndian<i16>>::read_from_little_endian_into Unexecuted instantiation: <_ as lebe::io::ReadEndian<i32>>::read_from_little_endian_into Unexecuted instantiation: <_ as lebe::io::ReadEndian<i64>>::read_from_little_endian_into Unexecuted instantiation: <_ as lebe::io::ReadEndian<i128>>::read_from_little_endian_into Unexecuted instantiation: <_ as lebe::io::ReadEndian<f32>>::read_from_little_endian_into Unexecuted instantiation: <_ as lebe::io::ReadEndian<f64>>::read_from_little_endian_into <exr::io::PeekRead<exr::io::Tracking<std::io::cursor::Cursor<alloc::vec::Vec<u8>>>> as lebe::io::ReadEndian<u8>>::read_from_little_endian_into Line | Count | Source | 406 | 16.3k | fn read_from_little_endian_into(&mut self, value: &mut $type) -> Result<()> { | 407 | 16.3k | unsafe { bytes::read_value(self, value)?; } | 408 | 16.3k | value.convert_little_endian_to_current(); | 409 | 16.3k | Ok(()) | 410 | 16.3k | } |
<exr::io::Tracking<std::io::cursor::Cursor<alloc::vec::Vec<u8>>> as lebe::io::ReadEndian<u8>>::read_from_little_endian_into Line | Count | Source | 406 | 936 | fn read_from_little_endian_into(&mut self, value: &mut $type) -> Result<()> { | 407 | 936 | unsafe { bytes::read_value(self, value)?; } | 408 | 936 | value.convert_little_endian_to_current(); | 409 | 936 | Ok(()) | 410 | 936 | } |
<exr::io::PeekRead<exr::io::Tracking<std::io::cursor::Cursor<alloc::vec::Vec<u8>>>> as lebe::io::ReadEndian<u32>>::read_from_little_endian_into Line | Count | Source | 406 | 78 | fn read_from_little_endian_into(&mut self, value: &mut $type) -> Result<()> { | 407 | 78 | unsafe { bytes::read_value(self, value)?; } | 408 | 78 | value.convert_little_endian_to_current(); | 409 | 78 | Ok(()) | 410 | 78 | } |
Unexecuted instantiation: <exr::io::PeekRead<exr::io::Tracking<std::io::cursor::Cursor<alloc::vec::Vec<u8>>>> as lebe::io::ReadEndian<u64>>::read_from_little_endian_into <exr::io::PeekRead<exr::io::Tracking<std::io::cursor::Cursor<alloc::vec::Vec<u8>>>> as lebe::io::ReadEndian<i32>>::read_from_little_endian_into Line | Count | Source | 406 | 3.61M | fn read_from_little_endian_into(&mut self, value: &mut $type) -> Result<()> { | 407 | 3.61M | unsafe { bytes::read_value(self, value)?; } | 408 | 3.61M | value.convert_little_endian_to_current(); | 409 | 3.61M | Ok(()) | 410 | 3.61M | } |
|
411 | | |
412 | | #[inline] |
413 | 0 | fn read_from_big_endian_into(&mut self, value: &mut $type) -> Result<()> { |
414 | 0 | unsafe { bytes::read_value(self, value)?; } |
415 | 0 | value.convert_big_endian_to_current(); |
416 | 0 | Ok(()) |
417 | 0 | } Unexecuted instantiation: <_ as lebe::io::ReadEndian<u8>>::read_from_big_endian_into Unexecuted instantiation: <_ as lebe::io::ReadEndian<u16>>::read_from_big_endian_into Unexecuted instantiation: <_ as lebe::io::ReadEndian<u32>>::read_from_big_endian_into Unexecuted instantiation: <_ as lebe::io::ReadEndian<u64>>::read_from_big_endian_into Unexecuted instantiation: <_ as lebe::io::ReadEndian<u128>>::read_from_big_endian_into Unexecuted instantiation: <_ as lebe::io::ReadEndian<i8>>::read_from_big_endian_into Unexecuted instantiation: <_ as lebe::io::ReadEndian<i16>>::read_from_big_endian_into Unexecuted instantiation: <_ as lebe::io::ReadEndian<i32>>::read_from_big_endian_into Unexecuted instantiation: <_ as lebe::io::ReadEndian<i64>>::read_from_big_endian_into Unexecuted instantiation: <_ as lebe::io::ReadEndian<i128>>::read_from_big_endian_into Unexecuted instantiation: <_ as lebe::io::ReadEndian<f32>>::read_from_big_endian_into Unexecuted instantiation: <_ as lebe::io::ReadEndian<f64>>::read_from_big_endian_into |
418 | | } |
419 | | }; |
420 | | } |
421 | | |
422 | | call_single_arg_macro_for_each! { |
423 | | implement_simple_primitive_write, |
424 | | u8, u16, u32, u64, u128, |
425 | | i8, i16, i32, i64, i128, |
426 | | f32, f64 |
427 | | } |
428 | | |
429 | | |
430 | | macro_rules! implement_slice_io { |
431 | | ($type: ident) => { |
432 | | impl<W: Write> WriteEndian<[$type]> for W { |
433 | 3.35M | fn write_as_little_endian(&mut self, value: &[$type]) -> Result<()> { |
434 | | #[cfg(target_endian = "big")] { |
435 | | for number in value { // TODO SIMD! |
436 | | self.write_as_little_endian(number)?; |
437 | | } |
438 | | } |
439 | | |
440 | | // else write whole slice |
441 | | #[cfg(target_endian = "little")] |
442 | 3.35M | unsafe { bytes::write_slice(self, value)?; } |
443 | | |
444 | 3.35M | Ok(()) |
445 | 3.35M | } <alloc::vec::Vec<u8> as lebe::io::WriteEndian<[u8]>>::write_as_little_endian Line | Count | Source | 433 | 393 | fn write_as_little_endian(&mut self, value: &[$type]) -> Result<()> { | 434 | | #[cfg(target_endian = "big")] { | 435 | | for number in value { // TODO SIMD! | 436 | | self.write_as_little_endian(number)?; | 437 | | } | 438 | | } | 439 | | | 440 | | // else write whole slice | 441 | | #[cfg(target_endian = "little")] | 442 | 393 | unsafe { bytes::write_slice(self, value)?; } | 443 | | | 444 | 393 | Ok(()) | 445 | 393 | } |
Unexecuted instantiation: <alloc::vec::Vec<u8> as lebe::io::WriteEndian<[u16]>>::write_as_little_endian Unexecuted instantiation: <std::io::cursor::Cursor<&mut [u8]> as lebe::io::WriteEndian<[f32]>>::write_as_little_endian Unexecuted instantiation: <std::io::cursor::Cursor<&mut [u8]> as lebe::io::WriteEndian<[u16]>>::write_as_little_endian Unexecuted instantiation: <std::io::cursor::Cursor<alloc::vec::Vec<u8>> as lebe::io::WriteEndian<[u32]>>::write_as_little_endian Unexecuted instantiation: <std::io::cursor::Cursor<&mut [u8]> as lebe::io::WriteEndian<[u32]>>::write_as_little_endian <&mut [u8] as lebe::io::WriteEndian<[u16]>>::write_as_little_endian Line | Count | Source | 433 | 2.63M | fn write_as_little_endian(&mut self, value: &[$type]) -> Result<()> { | 434 | | #[cfg(target_endian = "big")] { | 435 | | for number in value { // TODO SIMD! | 436 | | self.write_as_little_endian(number)?; | 437 | | } | 438 | | } | 439 | | | 440 | | // else write whole slice | 441 | | #[cfg(target_endian = "little")] | 442 | 2.63M | unsafe { bytes::write_slice(self, value)?; } | 443 | | | 444 | 2.63M | Ok(()) | 445 | 2.63M | } |
Unexecuted instantiation: <_ as lebe::io::WriteEndian<[i32]>>::write_as_little_endian Unexecuted instantiation: <_ as lebe::io::WriteEndian<[i64]>>::write_as_little_endian Unexecuted instantiation: <_ as lebe::io::WriteEndian<[i128]>>::write_as_little_endian Unexecuted instantiation: <_ as lebe::io::WriteEndian<[f64]>>::write_as_little_endian Unexecuted instantiation: <_ as lebe::io::WriteEndian<[f32]>>::write_as_little_endian Unexecuted instantiation: <_ as lebe::io::WriteEndian<[u8]>>::write_as_little_endian Unexecuted instantiation: <_ as lebe::io::WriteEndian<[u16]>>::write_as_little_endian Unexecuted instantiation: <_ as lebe::io::WriteEndian<[u32]>>::write_as_little_endian Unexecuted instantiation: <_ as lebe::io::WriteEndian<[u64]>>::write_as_little_endian Unexecuted instantiation: <_ as lebe::io::WriteEndian<[u128]>>::write_as_little_endian Unexecuted instantiation: <_ as lebe::io::WriteEndian<[i8]>>::write_as_little_endian Unexecuted instantiation: <_ as lebe::io::WriteEndian<[i16]>>::write_as_little_endian Unexecuted instantiation: <exr::io::Tracking<&mut &mut std::io::cursor::Cursor<alloc::vec::Vec<u8>>> as lebe::io::WriteEndian<[f32]>>::write_as_little_endian Unexecuted instantiation: <exr::io::Tracking<&mut &mut std::io::cursor::Cursor<alloc::vec::Vec<u8>>> as lebe::io::WriteEndian<[u8]>>::write_as_little_endian Unexecuted instantiation: <exr::io::Tracking<&mut &mut std::io::cursor::Cursor<alloc::vec::Vec<u8>>> as lebe::io::WriteEndian<[u64]>>::write_as_little_endian Unexecuted instantiation: <exr::io::Tracking<&mut &mut std::io::cursor::Cursor<alloc::vec::Vec<u8>>> as lebe::io::WriteEndian<[i8]>>::write_as_little_endian Unexecuted instantiation: <exr::io::Tracking<&mut std::io::cursor::Cursor<&mut alloc::vec::Vec<u8>>> as lebe::io::WriteEndian<[f32]>>::write_as_little_endian <exr::io::Tracking<&mut std::io::cursor::Cursor<&mut alloc::vec::Vec<u8>>> as lebe::io::WriteEndian<[u8]>>::write_as_little_endian Line | Count | Source | 433 | 725k | fn write_as_little_endian(&mut self, value: &[$type]) -> Result<()> { | 434 | | #[cfg(target_endian = "big")] { | 435 | | for number in value { // TODO SIMD! | 436 | | self.write_as_little_endian(number)?; | 437 | | } | 438 | | } | 439 | | | 440 | | // else write whole slice | 441 | | #[cfg(target_endian = "little")] | 442 | 725k | unsafe { bytes::write_slice(self, value)?; } | 443 | | | 444 | 725k | Ok(()) | 445 | 725k | } |
<exr::io::Tracking<&mut std::io::cursor::Cursor<&mut alloc::vec::Vec<u8>>> as lebe::io::WriteEndian<[u64]>>::write_as_little_endian Line | Count | Source | 433 | 78 | fn write_as_little_endian(&mut self, value: &[$type]) -> Result<()> { | 434 | | #[cfg(target_endian = "big")] { | 435 | | for number in value { // TODO SIMD! | 436 | | self.write_as_little_endian(number)?; | 437 | | } | 438 | | } | 439 | | | 440 | | // else write whole slice | 441 | | #[cfg(target_endian = "little")] | 442 | 78 | unsafe { bytes::write_slice(self, value)?; } | 443 | | | 444 | 78 | Ok(()) | 445 | 78 | } |
<exr::io::Tracking<&mut std::io::cursor::Cursor<&mut alloc::vec::Vec<u8>>> as lebe::io::WriteEndian<[i8]>>::write_as_little_endian Line | Count | Source | 433 | 312 | fn write_as_little_endian(&mut self, value: &[$type]) -> Result<()> { | 434 | | #[cfg(target_endian = "big")] { | 435 | | for number in value { // TODO SIMD! | 436 | | self.write_as_little_endian(number)?; | 437 | | } | 438 | | } | 439 | | | 440 | | // else write whole slice | 441 | | #[cfg(target_endian = "little")] | 442 | 312 | unsafe { bytes::write_slice(self, value)?; } | 443 | | | 444 | 312 | Ok(()) | 445 | 312 | } |
|
446 | | |
447 | 0 | fn write_as_big_endian(&mut self, value: &[$type]) -> Result<()> { |
448 | | #[cfg(target_endian = "little")] { |
449 | 0 | for number in value { // TODO SIMD! |
450 | 0 | self.write_as_big_endian(number)?; |
451 | | } |
452 | | } |
453 | | |
454 | | // else write whole slice |
455 | | #[cfg(target_endian = "big")] |
456 | | unsafe { bytes::write_slice(self, value)?; } |
457 | | |
458 | 0 | Ok(()) |
459 | 0 | } Unexecuted instantiation: <_ as lebe::io::WriteEndian<[i32]>>::write_as_big_endian Unexecuted instantiation: <_ as lebe::io::WriteEndian<[i64]>>::write_as_big_endian Unexecuted instantiation: <_ as lebe::io::WriteEndian<[i128]>>::write_as_big_endian Unexecuted instantiation: <_ as lebe::io::WriteEndian<[f64]>>::write_as_big_endian Unexecuted instantiation: <_ as lebe::io::WriteEndian<[f32]>>::write_as_big_endian Unexecuted instantiation: <_ as lebe::io::WriteEndian<[u8]>>::write_as_big_endian Unexecuted instantiation: <_ as lebe::io::WriteEndian<[u16]>>::write_as_big_endian Unexecuted instantiation: <_ as lebe::io::WriteEndian<[u32]>>::write_as_big_endian Unexecuted instantiation: <_ as lebe::io::WriteEndian<[u64]>>::write_as_big_endian Unexecuted instantiation: <_ as lebe::io::WriteEndian<[u128]>>::write_as_big_endian Unexecuted instantiation: <_ as lebe::io::WriteEndian<[i8]>>::write_as_big_endian Unexecuted instantiation: <_ as lebe::io::WriteEndian<[i16]>>::write_as_big_endian |
460 | | } |
461 | | |
462 | | impl<R: Read> ReadEndian<[$type]> for R { |
463 | 69.5M | fn read_from_little_endian_into(&mut self, value: &mut [$type]) -> Result<()> { |
464 | 69.5M | unsafe { bytes::read_slice(self, value)? }; |
465 | 69.5M | value.convert_little_endian_to_current(); |
466 | 69.5M | Ok(()) |
467 | 69.5M | } <exr::io::PeekRead<exr::io::Tracking<std::io::cursor::Cursor<&[u8]>>> as lebe::io::ReadEndian<[u8]>>::read_from_little_endian_into Line | Count | Source | 463 | 1.75M | fn read_from_little_endian_into(&mut self, value: &mut [$type]) -> Result<()> { | 464 | 1.75M | unsafe { bytes::read_slice(self, value)? }; | 465 | 1.75M | value.convert_little_endian_to_current(); | 466 | 1.75M | Ok(()) | 467 | 1.75M | } |
<exr::io::PeekRead<&[u8]> as lebe::io::ReadEndian<[u8]>>::read_from_little_endian_into Line | Count | Source | 463 | 1.60k | fn read_from_little_endian_into(&mut self, value: &mut [$type]) -> Result<()> { | 464 | 1.60k | unsafe { bytes::read_slice(self, value)? }; | 465 | 1.59k | value.convert_little_endian_to_current(); | 466 | 1.59k | Ok(()) | 467 | 1.60k | } |
<exr::io::PeekRead<exr::io::Tracking<std::io::cursor::Cursor<&[u8]>>> as lebe::io::ReadEndian<[u64]>>::read_from_little_endian_into Line | Count | Source | 463 | 17.1k | fn read_from_little_endian_into(&mut self, value: &mut [$type]) -> Result<()> { | 464 | 17.1k | unsafe { bytes::read_slice(self, value)? }; | 465 | 16.9k | value.convert_little_endian_to_current(); | 466 | 16.9k | Ok(()) | 467 | 17.1k | } |
Unexecuted instantiation: <exr::io::PeekRead<exr::io::Tracking<std::io::cursor::Cursor<&[u8]>>> as lebe::io::ReadEndian<[i8]>>::read_from_little_endian_into <exr::io::PeekRead<&[u8]> as lebe::io::ReadEndian<[i8]>>::read_from_little_endian_into Line | Count | Source | 463 | 197k | fn read_from_little_endian_into(&mut self, value: &mut [$type]) -> Result<()> { | 464 | 197k | unsafe { bytes::read_slice(self, value)? }; | 465 | 197k | value.convert_little_endian_to_current(); | 466 | 197k | Ok(()) | 467 | 197k | } |
<&mut &mut &[u8] as lebe::io::ReadEndian<[f32]>>::read_from_little_endian_into Line | Count | Source | 463 | 66.5M | fn read_from_little_endian_into(&mut self, value: &mut [$type]) -> Result<()> { | 464 | 66.5M | unsafe { bytes::read_slice(self, value)? }; | 465 | 66.5M | value.convert_little_endian_to_current(); | 466 | 66.5M | Ok(()) | 467 | 66.5M | } |
<&[u8] as lebe::io::ReadEndian<[f32]>>::read_from_little_endian_into Line | Count | Source | 463 | 22.3k | fn read_from_little_endian_into(&mut self, value: &mut [$type]) -> Result<()> { | 464 | 22.3k | unsafe { bytes::read_slice(self, value)? }; | 465 | 22.3k | value.convert_little_endian_to_current(); | 466 | 22.3k | Ok(()) | 467 | 22.3k | } |
<&mut &mut &[u8] as lebe::io::ReadEndian<[u16]>>::read_from_little_endian_into Line | Count | Source | 463 | 127k | fn read_from_little_endian_into(&mut self, value: &mut [$type]) -> Result<()> { | 464 | 127k | unsafe { bytes::read_slice(self, value)? }; | 465 | 127k | value.convert_little_endian_to_current(); | 466 | 127k | Ok(()) | 467 | 127k | } |
<&mut &mut &[u8] as lebe::io::ReadEndian<[u32]>>::read_from_little_endian_into Line | Count | Source | 463 | 64.9k | fn read_from_little_endian_into(&mut self, value: &mut [$type]) -> Result<()> { | 464 | 64.9k | unsafe { bytes::read_slice(self, value)? }; | 465 | 64.9k | value.convert_little_endian_to_current(); | 466 | 64.9k | Ok(()) | 467 | 64.9k | } |
<&[u8] as lebe::io::ReadEndian<[i8]>>::read_from_little_endian_into Line | Count | Source | 463 | 2.67k | fn read_from_little_endian_into(&mut self, value: &mut [$type]) -> Result<()> { | 464 | 2.67k | unsafe { bytes::read_slice(self, value)? }; | 465 | 2.66k | value.convert_little_endian_to_current(); | 466 | 2.66k | Ok(()) | 467 | 2.67k | } |
Unexecuted instantiation: <std::io::cursor::Cursor<&[u8]> as lebe::io::ReadEndian<[f32]>>::read_from_little_endian_into Unexecuted instantiation: <std::io::cursor::Cursor<&[u8]> as lebe::io::ReadEndian<[u16]>>::read_from_little_endian_into Unexecuted instantiation: <std::io::cursor::Cursor<&[u8]> as lebe::io::ReadEndian<[u32]>>::read_from_little_endian_into <&[u8] as lebe::io::ReadEndian<[u8]>>::read_from_little_endian_into Line | Count | Source | 463 | 28.6k | fn read_from_little_endian_into(&mut self, value: &mut [$type]) -> Result<()> { | 464 | 28.6k | unsafe { bytes::read_slice(self, value)? }; | 465 | 28.6k | value.convert_little_endian_to_current(); | 466 | 28.6k | Ok(()) | 467 | 28.6k | } |
Unexecuted instantiation: <&[u8] as lebe::io::ReadEndian<[u16]>>::read_from_little_endian_into Unexecuted instantiation: <_ as lebe::io::ReadEndian<[i16]>>::read_from_little_endian_into Unexecuted instantiation: <_ as lebe::io::ReadEndian<[i32]>>::read_from_little_endian_into Unexecuted instantiation: <_ as lebe::io::ReadEndian<[i64]>>::read_from_little_endian_into Unexecuted instantiation: <_ as lebe::io::ReadEndian<[i128]>>::read_from_little_endian_into Unexecuted instantiation: <_ as lebe::io::ReadEndian<[f64]>>::read_from_little_endian_into Unexecuted instantiation: <_ as lebe::io::ReadEndian<[f32]>>::read_from_little_endian_into Unexecuted instantiation: <_ as lebe::io::ReadEndian<[u8]>>::read_from_little_endian_into Unexecuted instantiation: <_ as lebe::io::ReadEndian<[u16]>>::read_from_little_endian_into Unexecuted instantiation: <_ as lebe::io::ReadEndian<[u32]>>::read_from_little_endian_into Unexecuted instantiation: <_ as lebe::io::ReadEndian<[u64]>>::read_from_little_endian_into Unexecuted instantiation: <_ as lebe::io::ReadEndian<[u128]>>::read_from_little_endian_into Unexecuted instantiation: <_ as lebe::io::ReadEndian<[i8]>>::read_from_little_endian_into <exr::io::PeekRead<exr::io::Tracking<std::io::cursor::Cursor<alloc::vec::Vec<u8>>>> as lebe::io::ReadEndian<[u8]>>::read_from_little_endian_into Line | Count | Source | 463 | 723k | fn read_from_little_endian_into(&mut self, value: &mut [$type]) -> Result<()> { | 464 | 723k | unsafe { bytes::read_slice(self, value)? }; | 465 | 723k | value.convert_little_endian_to_current(); | 466 | 723k | Ok(()) | 467 | 723k | } |
<exr::io::PeekRead<exr::io::Tracking<std::io::cursor::Cursor<alloc::vec::Vec<u8>>>> as lebe::io::ReadEndian<[u64]>>::read_from_little_endian_into Line | Count | Source | 463 | 81 | fn read_from_little_endian_into(&mut self, value: &mut [$type]) -> Result<()> { | 464 | 81 | unsafe { bytes::read_slice(self, value)? }; | 465 | 81 | value.convert_little_endian_to_current(); | 466 | 81 | Ok(()) | 467 | 81 | } |
Unexecuted instantiation: <exr::io::PeekRead<exr::io::Tracking<std::io::cursor::Cursor<alloc::vec::Vec<u8>>>> as lebe::io::ReadEndian<[i8]>>::read_from_little_endian_into |
468 | | |
469 | 0 | fn read_from_big_endian_into(&mut self, value: &mut [$type]) -> Result<()> { |
470 | 0 | unsafe { bytes::read_slice(self, value)? }; |
471 | 0 | value.convert_big_endian_to_current(); |
472 | 0 | Ok(()) |
473 | 0 | } Unexecuted instantiation: <_ as lebe::io::ReadEndian<[i16]>>::read_from_big_endian_into Unexecuted instantiation: <_ as lebe::io::ReadEndian<[i32]>>::read_from_big_endian_into Unexecuted instantiation: <_ as lebe::io::ReadEndian<[i64]>>::read_from_big_endian_into Unexecuted instantiation: <_ as lebe::io::ReadEndian<[i128]>>::read_from_big_endian_into Unexecuted instantiation: <_ as lebe::io::ReadEndian<[f64]>>::read_from_big_endian_into Unexecuted instantiation: <_ as lebe::io::ReadEndian<[f32]>>::read_from_big_endian_into Unexecuted instantiation: <_ as lebe::io::ReadEndian<[u8]>>::read_from_big_endian_into Unexecuted instantiation: <_ as lebe::io::ReadEndian<[u16]>>::read_from_big_endian_into Unexecuted instantiation: <_ as lebe::io::ReadEndian<[u32]>>::read_from_big_endian_into Unexecuted instantiation: <_ as lebe::io::ReadEndian<[u64]>>::read_from_big_endian_into Unexecuted instantiation: <_ as lebe::io::ReadEndian<[u128]>>::read_from_big_endian_into Unexecuted instantiation: <_ as lebe::io::ReadEndian<[i8]>>::read_from_big_endian_into |
474 | | } |
475 | | }; |
476 | | } |
477 | | |
478 | | call_single_arg_macro_for_each! { |
479 | | implement_slice_io, |
480 | | u8, u16, u32, u64, u128, |
481 | | i8, i16, i32, i64, i128, |
482 | | f64, f32 |
483 | | } |
484 | | |
485 | | |
486 | | |
487 | | // TODO: SIMD |
488 | | /*impl<R: Read> ReadEndian<[f32]> for R { |
489 | | fn read_from_little_endian_into(&mut self, value: &mut [f32]) -> Result<()> { |
490 | | unsafe { bytes::read_slice(self, value)? }; |
491 | | value.convert_little_endian_to_current(); |
492 | | Ok(()) |
493 | | } |
494 | | |
495 | | fn read_from_big_endian_into(&mut self, value: &mut [f32]) -> Result<()> { |
496 | | unsafe { bytes::read_slice(self, value)? }; |
497 | | value.convert_big_endian_to_current(); |
498 | | Ok(()) |
499 | | } |
500 | | } |
501 | | |
502 | | impl<W: Write> WriteEndian<[f32]> for W { |
503 | | fn write_as_big_endian(&mut self, value: &[f32]) -> Result<()> { |
504 | | if cfg!(target_endian = "little") { |
505 | | |
506 | | // FIX ME this SIMD optimization makes no difference ... why? like, ZERO difference, not even worse |
507 | | // #[cfg(feature = "simd")] |
508 | | #[cfg(any(target_arch = "x86", target_arch = "x86_64"))] |
509 | | unsafe { |
510 | | if is_x86_feature_detected!("avx2") { |
511 | | write_bytes_avx(self, value); |
512 | | return Ok(()); |
513 | | } |
514 | | } |
515 | | |
516 | | // otherwise (no avx2 available) |
517 | | // for number in value { |
518 | | // self.write_as_little_endian(number); |
519 | | // } |
520 | | // |
521 | | // return Ok(()); |
522 | | unimplemented!(); |
523 | | |
524 | | #[target_feature(enable = "avx2")] |
525 | | #[cfg(any(target_arch = "x86", target_arch = "x86_64"))] |
526 | | unsafe fn write_bytes_avx(write: &mut impl Write, slice: &[f32]) -> Result<()> { |
527 | | #[cfg(target_arch = "x86")] use std::arch::x86 as mm; |
528 | | #[cfg(target_arch = "x86_64")] use std::arch::x86_64 as mm; |
529 | | |
530 | | let bytes: &[u8] = crate::io::bytes::slice_as_bytes(slice); |
531 | | let mut chunks = bytes.chunks_exact(32); |
532 | | |
533 | | let indices = mm::_mm256_set_epi8( |
534 | | 0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15, |
535 | | 0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15 |
536 | | // 3,2,1,0, 7,6,5,4, 11,10,9,8, 15,14,13,12, |
537 | | // 3,2,1,0, 7,6,5,4, 11,10,9,8, 15,14,13,12 |
538 | | ); |
539 | | |
540 | | for chunk in &mut chunks { |
541 | | let data = mm::_mm256_loadu_si256(chunk.as_ptr() as _); |
542 | | let result = mm::_mm256_shuffle_epi8(data, indices); |
543 | | let mut out = [0_u8; 32]; |
544 | | mm::_mm256_storeu_si256(out.as_mut_ptr() as _, result); |
545 | | write.write_all(&out)?; |
546 | | } |
547 | | |
548 | | let remainder = chunks.remainder(); |
549 | | |
550 | | { // copy remainder into larger slice, with zeroes at the end |
551 | | let mut last_chunk = [0_u8; 32]; |
552 | | last_chunk[0..remainder.len()].copy_from_slice(remainder); |
553 | | let data = mm::_mm256_loadu_si256(last_chunk.as_ptr() as _); |
554 | | let result = mm::_mm256_shuffle_epi8(data, indices); |
555 | | mm::_mm256_storeu_si256(last_chunk.as_mut_ptr() as _, result); |
556 | | write.write_all(&last_chunk[0..remainder.len()])?; |
557 | | } |
558 | | |
559 | | Ok(()) |
560 | | } |
561 | | } |
562 | | |
563 | | else { |
564 | | unsafe { bytes::write_slice(self, value)?; } |
565 | | Ok(()) |
566 | | } |
567 | | } |
568 | | |
569 | | fn write_as_little_endian(&mut self, value: &[f32]) -> Result<()> { |
570 | | for number in value { |
571 | | self.write_as_little_endian(number)?; |
572 | | } |
573 | | |
574 | | Ok(()) |
575 | | } |
576 | | }*/ |
577 | | } |
578 | | |