diff --git a/src/decoder/stream.rs b/src/decoder/stream.rs index 6330969..c7781c2 100644 --- a/src/decoder/stream.rs +++ b/src/decoder/stream.rs @@ -1,14 +1,7 @@ //! All IO functionality needed for TIFF decoding use std::io::{self, BufRead, BufReader, Read, Seek, Take}; -/// Byte order of the TIFF file. -#[derive(Clone, Copy, Debug)] -pub enum ByteOrder { - /// little endian byte order - LittleEndian, - /// big endian byte order - BigEndian, -} +pub use crate::tags::ByteOrder; /// Reader that is aware of the byte order. #[derive(Debug)] diff --git a/src/tags.rs b/src/tags.rs index f9634b2..8592f0b 100644 --- a/src/tags.rs +++ b/src/tags.rs @@ -296,3 +296,30 @@ pub enum SampleFormat(u16) unknown( Void = 4, } } + +/// Byte order of the TIFF file. +#[derive(Clone, Copy, Debug, PartialEq, Eq)] +pub enum ByteOrder { + /// little endian byte order + LittleEndian, + /// big endian byte order + BigEndian, +} + +impl ByteOrder { + /// Get the byte order representing the running target. + /// + /// The infallibility of this method represents the fact that only little and big endian + /// systems are supported by the library. No mixed endian and no other weird stuff. (Note: as + /// of Rust 1.90 this is a tautology as Rust itself only has those two kinds). + pub const fn native() -> Self { + match () { + #[cfg(target_endian = "little")] + () => ByteOrder::LittleEndian, + #[cfg(target_endian = "big")] + () => ByteOrder::BigEndian, + #[cfg(not(any(target_endian = "big", target_endian = "little")))] + () => compile_error!("Unsupported target"), + } + } +}