/rust/registry/src/index.crates.io-1949cf8c6b5b557f/png-0.18.1/src/traits.rs
Line | Count | Source |
1 | | use std::io; |
2 | | |
3 | | macro_rules! read_bytes_ext { |
4 | | ($output_type:ty) => { |
5 | | impl<W: io::Read + ?Sized> ReadBytesExt<$output_type> for W { |
6 | | #[inline] |
7 | 154k | fn read_be(&mut self) -> io::Result<$output_type> { |
8 | 154k | let mut bytes = [0u8; std::mem::size_of::<$output_type>()]; |
9 | 154k | self.read_exact(&mut bytes)?; |
10 | 154k | Ok(<$output_type>::from_be_bytes(bytes)) |
11 | 154k | } <&[u8] as png::traits::ReadBytesExt<u8>>::read_be Line | Count | Source | 7 | 113k | fn read_be(&mut self) -> io::Result<$output_type> { | 8 | 113k | let mut bytes = [0u8; std::mem::size_of::<$output_type>()]; | 9 | 113k | self.read_exact(&mut bytes)?; | 10 | 113k | Ok(<$output_type>::from_be_bytes(bytes)) | 11 | 113k | } |
<&[u8] as png::traits::ReadBytesExt<u32>>::read_be Line | Count | Source | 7 | 39.7k | fn read_be(&mut self) -> io::Result<$output_type> { | 8 | 39.7k | let mut bytes = [0u8; std::mem::size_of::<$output_type>()]; | 9 | 39.7k | self.read_exact(&mut bytes)?; | 10 | 39.7k | Ok(<$output_type>::from_be_bytes(bytes)) | 11 | 39.7k | } |
<&[u8] as png::traits::ReadBytesExt<u16>>::read_be Line | Count | Source | 7 | 1.08k | fn read_be(&mut self) -> io::Result<$output_type> { | 8 | 1.08k | let mut bytes = [0u8; std::mem::size_of::<$output_type>()]; | 9 | 1.08k | self.read_exact(&mut bytes)?; | 10 | 1.08k | Ok(<$output_type>::from_be_bytes(bytes)) | 11 | 1.08k | } |
|
12 | | } |
13 | | }; |
14 | | } |
15 | | |
16 | | macro_rules! write_bytes_ext { |
17 | | ($input_type:ty) => { |
18 | | impl<W: io::Write + ?Sized> WriteBytesExt<$input_type> for W { |
19 | | #[inline] |
20 | 0 | fn write_be(&mut self, n: $input_type) -> io::Result<()> { |
21 | 0 | self.write_all(&n.to_be_bytes()) |
22 | 0 | } Unexecuted instantiation: <&mut &mut alloc::vec::Vec<u8> as png::traits::WriteBytesExt<u32>>::write_be Unexecuted instantiation: <_ as png::traits::WriteBytesExt<u32>>::write_be Unexecuted instantiation: <&mut &mut std::io::cursor::Cursor<alloc::vec::Vec<u8>> as png::traits::WriteBytesExt<u32>>::write_be |
23 | | } |
24 | | }; |
25 | | } |
26 | | |
27 | | /// Read extension to read big endian data |
28 | | pub trait ReadBytesExt<T>: io::Read { |
29 | | /// Read `T` from a bytes stream. Most significant byte first. |
30 | | fn read_be(&mut self) -> io::Result<T>; |
31 | | } |
32 | | |
33 | | /// Write extension to write big endian data |
34 | | pub trait WriteBytesExt<T>: io::Write { |
35 | | /// Writes `T` to a bytes stream. Most significant byte first. |
36 | | fn write_be(&mut self, _: T) -> io::Result<()>; |
37 | | } |
38 | | |
39 | | read_bytes_ext!(u8); |
40 | | read_bytes_ext!(u16); |
41 | | read_bytes_ext!(u32); |
42 | | |
43 | | write_bytes_ext!(u32); |