Recently, while creating a TIFF decoder in Rust ran into a frequent issue
in parser legibility - endianness. Typically, a file format will specify an
endianness globally through it's specification, or will include a marker in
it's header to indicate the endianness with which the file was saved. Usually,
at this point a parser devolves into a series of scalar type and endianness
specific calls, such as 'htons', or custom conversion functions like
'read_u32_le', which can reduce legibility and makes implementations more
error prone. This pattern is also difficult to work with in file formats
where both endiannesses are permitted, such as TIFF, where endianness is
selected based on values read from the header. In this article we introduce
an abstraction in Rust which leans on type-inference to abstract away scalar
type specific functions when parsing data from a stream.
More info