From 721d438b620d1ded126e0386003f6aeb0c80d091 Mon Sep 17 00:00:00 2001 From: martinfrances107 Date: Fri, 15 Mar 2024 09:11:46 +0000 Subject: [PATCH 1/3] enum Values now derives PartialEq. --- src/value.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/value.rs b/src/value.rs index e05743c..d36e35c 100644 --- a/src/value.rs +++ b/src/value.rs @@ -31,7 +31,7 @@ use crate::endian::Endian; use crate::error::Error; /// A type and values of a TIFF/Exif field. -#[derive(Clone)] +#[derive(Clone, PartialEq)] pub enum Value { /// Vector of 8-bit unsigned integers. Byte(Vec), @@ -346,7 +346,7 @@ impl From<&DefaultValue> for Option { } /// An unsigned rational number, which is a pair of 32-bit unsigned integers. -#[derive(Copy, Clone)] +#[derive(Copy, Clone, PartialEq)] pub struct Rational { pub num: u32, pub denom: u32 } impl Rational { @@ -384,7 +384,7 @@ impl fmt::Display for Rational { } /// A signed rational number, which is a pair of 32-bit signed integers. -#[derive(Copy, Clone)] +#[derive(Copy, Clone, PartialEq)] pub struct SRational { pub num: i32, pub denom: i32 } impl SRational { From 4db2310aa90a63bc346f756b71f4dbee891e9f59 Mon Sep 17 00:00:00 2001 From: martinfrances107 Date: Fri, 15 Mar 2024 10:10:57 +0000 Subject: [PATCH 2/3] Field now derrived PartialEq. --- src/tiff.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/tiff.rs b/src/tiff.rs index 26af106..d3baa28 100644 --- a/src/tiff.rs +++ b/src/tiff.rs @@ -99,7 +99,7 @@ impl IfdEntry { } /// A TIFF/Exif field. -#[derive(Debug, Clone)] +#[derive(Debug, Clone, PartialEq)] pub struct Field { /// The tag of this field. pub tag: Tag, From e7cc7bcdb13fb8c80bbe983e61022481edb86531 Mon Sep 17 00:00:00 2001 From: martinfrances107 Date: Mon, 29 Apr 2024 17:50:28 +0100 Subject: [PATCH 3/3] Field and its dependant structs now support Deserialize/Serialize. photo_indexer needed to pass Field from server to client. --- Cargo.toml | 1 + src/tag.rs | 7 +++++-- src/tiff.rs | 6 ++++-- src/value.rs | 9 ++++++--- 4 files changed, 16 insertions(+), 7 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 04e338a..3ad9b64 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -16,3 +16,4 @@ license = "BSD-2-Clause" [dependencies] mutate_once = "0.1.1" +serde = { version = "~1", features = ["derive"] } diff --git a/src/tag.rs b/src/tag.rs index d0dd479..3ac4e5a 100644 --- a/src/tag.rs +++ b/src/tag.rs @@ -26,6 +26,9 @@ use std::fmt; +use serde::Deserialize; +use serde::Serialize; + use crate::error::Error; use crate::value; use crate::value::Value; @@ -55,7 +58,7 @@ use crate::util::atou16; // PartialEq and Eq need to be _automatically derived_ for Tag to // emulate structural equivalency. // -#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)] +#[derive(Debug, Copy, Clone, Deserialize, PartialEq, Eq, PartialOrd, Ord, Hash, Serialize)] pub struct Tag(pub Context, pub u16); impl Tag { @@ -113,7 +116,7 @@ impl fmt::Display for Tag { } /// An enum that indicates how a tag number is interpreted. -#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)] +#[derive(Debug, Copy, Clone, Deserialize, PartialEq, Eq, PartialOrd, Ord, Hash, Serialize)] #[non_exhaustive] pub enum Context { /// TIFF attributes defined in the TIFF Rev. 6.0 specification. diff --git a/src/tiff.rs b/src/tiff.rs index d3baa28..79887aa 100644 --- a/src/tiff.rs +++ b/src/tiff.rs @@ -26,6 +26,8 @@ use std::fmt; use mutate_once::MutOnce; +use serde::Deserialize; +use serde::Serialize; use crate::endian::{Endian, BigEndian, LittleEndian}; use crate::error::Error; @@ -99,7 +101,7 @@ impl IfdEntry { } /// A TIFF/Exif field. -#[derive(Debug, Clone, PartialEq)] +#[derive(Debug, Clone, Deserialize, PartialEq, Serialize)] pub struct Field { /// The tag of this field. pub tag: Tag, @@ -121,7 +123,7 @@ pub struct Field { /// assert_eq!(In::PRIMARY.index(), 0); /// assert_eq!(In::THUMBNAIL.index(), 1); /// ``` -#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)] +#[derive(Debug, Copy, Clone, Deserialize, PartialEq, Eq, PartialOrd, Ord, Hash, Serialize)] pub struct In(pub u16); impl In { diff --git a/src/value.rs b/src/value.rs index d36e35c..e8a2acf 100644 --- a/src/value.rs +++ b/src/value.rs @@ -27,11 +27,14 @@ use std::fmt; use std::fmt::Write as _; +use serde::Deserialize; +use serde::Serialize; + use crate::endian::Endian; use crate::error::Error; /// A type and values of a TIFF/Exif field. -#[derive(Clone, PartialEq)] +#[derive(Clone, Deserialize, PartialEq, Serialize)] pub enum Value { /// Vector of 8-bit unsigned integers. Byte(Vec), @@ -346,7 +349,7 @@ impl From<&DefaultValue> for Option { } /// An unsigned rational number, which is a pair of 32-bit unsigned integers. -#[derive(Copy, Clone, PartialEq)] +#[derive(Copy, Clone, Deserialize, PartialEq, Serialize)] pub struct Rational { pub num: u32, pub denom: u32 } impl Rational { @@ -384,7 +387,7 @@ impl fmt::Display for Rational { } /// A signed rational number, which is a pair of 32-bit signed integers. -#[derive(Copy, Clone, PartialEq)] +#[derive(Copy, Clone, Deserialize, PartialEq, Serialize)] pub struct SRational { pub num: i32, pub denom: i32 } impl SRational {