Tags: restore primitive conversions as inherent methods
This commit is contained in:
1 parent
1c8e98bca5
commit
ec0477125f
3 files changed
+24
-29
No files matched your search
+1
-1
@@ -6,7 +6,7 @@ use std::cmp;
|
|||||||
use {ColorType, TiffError, TiffFormatError, TiffResult, TiffUnsupportedError};
|
use {ColorType, TiffError, TiffFormatError, TiffResult, TiffUnsupportedError};
|
||||||
|
|
||||||
use self::ifd::Directory;
|
use self::ifd::Directory;
|
||||||
use tags::{CompressionMethod, PhotometricInterpretation, Predictor, Tag, Type, U16Tag};
|
use tags::{CompressionMethod, PhotometricInterpretation, Predictor, Tag, Type};
|
||||||
|
|
||||||
use self::stream::{ByteOrder, EndianReader, LZWReader, DeflateReader, PackBitsReader, SmartReader};
|
use self::stream::{ByteOrder, EndianReader, LZWReader, DeflateReader, PackBitsReader, SmartReader};
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -4,7 +4,7 @@ use std::convert::TryFrom;
|
|||||||
use std::io::{Seek, Write};
|
use std::io::{Seek, Write};
|
||||||
use std::mem;
|
use std::mem;
|
||||||
|
|
||||||
use tags::{self, ResolutionUnit, Tag, Type, U16Tag};
|
use tags::{self, ResolutionUnit, Tag, Type};
|
||||||
use error::{TiffError, TiffFormatError, TiffResult};
|
use error::{TiffError, TiffFormatError, TiffResult};
|
||||||
|
|
||||||
pub mod colortype;
|
pub mod colortype;
|
||||||
|
|||||||
+22
-27
@@ -1,32 +1,8 @@
|
|||||||
mod seals {
|
|
||||||
pub trait TagConversion<T>: Sized {
|
|
||||||
fn __from_inner_type(T) -> Result<Self, T>;
|
|
||||||
|
|
||||||
fn __to_inner_type(&self) -> T;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub trait U16Tag: Sized {
|
|
||||||
fn from_u16(val: u16) -> Option<Self>;
|
|
||||||
|
|
||||||
fn to_u16(&self) -> u16;
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<T: seals::TagConversion<u16>> U16Tag for T {
|
|
||||||
fn from_u16(val: u16) -> Option<Self> {
|
|
||||||
Self::__from_inner_type(val).ok()
|
|
||||||
}
|
|
||||||
|
|
||||||
fn to_u16(&self) -> u16 {
|
|
||||||
Self::__to_inner_type(self)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
macro_rules! tags {
|
macro_rules! tags {
|
||||||
{
|
{
|
||||||
// Permit arbitrary meta items, which include documentation.
|
// Permit arbitrary meta items, which include documentation.
|
||||||
$( #[$enum_attr:meta] )*
|
$( #[$enum_attr:meta] )*
|
||||||
$vis:vis enum $name:ident($ty:ty) $(unknown($unknown_doc:literal))* {
|
$vis:vis enum $name:ident($ty:tt) $(unknown($unknown_doc:literal))* {
|
||||||
// Each of the `Name = Val,` permitting documentation.
|
// Each of the `Name = Val,` permitting documentation.
|
||||||
$($(#[$ident_attr:meta])* $tag:ident = $val:expr,)*
|
$($(#[$ident_attr:meta])* $tag:ident = $val:expr,)*
|
||||||
}
|
}
|
||||||
@@ -44,7 +20,7 @@ macro_rules! tags {
|
|||||||
)*
|
)*
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ::tags::seals::TagConversion<$ty> for $name {
|
impl $name {
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
fn __from_inner_type(n: $ty) -> Result<Self, $ty> {
|
fn __from_inner_type(n: $ty) -> Result<Self, $ty> {
|
||||||
match n {
|
match n {
|
||||||
@@ -62,7 +38,26 @@ macro_rules! tags {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
tags!($name, $ty);
|
||||||
|
};
|
||||||
|
// For u16 tags, provide direct inherent primitive conversion methods.
|
||||||
|
($name:tt, u16) => {
|
||||||
|
impl $name {
|
||||||
|
#[inline(always)]
|
||||||
|
pub fn from_u16(val: u16) -> Option<Self> {
|
||||||
|
Self::__from_inner_type(val).ok()
|
||||||
|
}
|
||||||
|
|
||||||
|
#[inline(always)]
|
||||||
|
pub fn to_u16(&self) -> u16 {
|
||||||
|
Self::__to_inner_type(self)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
// For other tag types, do nothing for now. With concat_idents one could
|
||||||
|
// provide inherent conversion methods for all types.
|
||||||
|
($name:tt, $ty:tt) => {};
|
||||||
}
|
}
|
||||||
|
|
||||||
// Note: These tags appear in the order they are mentioned in the TIFF reference
|
// Note: These tags appear in the order they are mentioned in the TIFF reference
|
||||||
|
|||||||
Reference in new issue
Block a user