From 517638a38fe4edbeb22ea2219048f978fb088330 Mon Sep 17 00:00:00 2001 From: Andreas Molzer Date: Sun, 10 Nov 2019 23:07:55 +0100 Subject: [PATCH] Prefer explicit conversion over `as` MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The discriminant of some enum types can be retrieved with the `as` operator and in C style enums it is also possible to set a specific discriminant. However, that may silently change—breaking the value written to the file. It is better to use that technique mostly for ffi purposes. --- src/encoder/mod.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/encoder/mod.rs b/src/encoder/mod.rs index 96ba414..f09b0a9 100644 --- a/src/encoder/mod.rs +++ b/src/encoder/mod.rs @@ -438,7 +438,7 @@ impl<'a, W: 'a + Write + Seek> DirectoryEncoder<'a, W> { } self.ifd - .insert(tag.to_u16(), (::FIELD_TYPE as u16, value.count(), bytes)); + .insert(tag.to_u16(), (::FIELD_TYPE.to_u16(), value.count(), bytes)); } fn write_directory(&mut self) -> TiffResult { @@ -565,7 +565,7 @@ impl<'a, W: 'a + Write + Seek, T: ColorType> ImageEncoder<'a, W, T> { encoder.write_tag(Tag::Compression, 1u16); encoder.write_tag(Tag::BitsPerSample, ::BITS_PER_SAMPLE); - encoder.write_tag(Tag::PhotometricInterpretation, ::TIFF_VALUE as u16); + encoder.write_tag(Tag::PhotometricInterpretation, ::TIFF_VALUE.to_u16()); encoder.write_tag(Tag::RowsPerStrip, rows_per_strip as u32);