Skip to content

Commit e7cc7bc

Browse files
Field and its dependant structs now support Deserialize/Serialize. photo_indexer needed to pass Field from server to client.
1 parent 4db2310 commit e7cc7bc

File tree

4 files changed

+16
-7
lines changed

4 files changed

+16
-7
lines changed

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,4 @@ license = "BSD-2-Clause"
1616

1717
[dependencies]
1818
mutate_once = "0.1.1"
19+
serde = { version = "~1", features = ["derive"] }

src/tag.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@
2626

2727
use std::fmt;
2828

29+
use serde::Deserialize;
30+
use serde::Serialize;
31+
2932
use crate::error::Error;
3033
use crate::value;
3134
use crate::value::Value;
@@ -55,7 +58,7 @@ use crate::util::atou16;
5558
// PartialEq and Eq need to be _automatically derived_ for Tag to
5659
// emulate structural equivalency.
5760
// <https://github.com/rust-lang/rfcs/pull/1445>
58-
#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
61+
#[derive(Debug, Copy, Clone, Deserialize, PartialEq, Eq, PartialOrd, Ord, Hash, Serialize)]
5962
pub struct Tag(pub Context, pub u16);
6063

6164
impl Tag {
@@ -113,7 +116,7 @@ impl fmt::Display for Tag {
113116
}
114117

115118
/// An enum that indicates how a tag number is interpreted.
116-
#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
119+
#[derive(Debug, Copy, Clone, Deserialize, PartialEq, Eq, PartialOrd, Ord, Hash, Serialize)]
117120
#[non_exhaustive]
118121
pub enum Context {
119122
/// TIFF attributes defined in the TIFF Rev. 6.0 specification.

src/tiff.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@
2626

2727
use std::fmt;
2828
use mutate_once::MutOnce;
29+
use serde::Deserialize;
30+
use serde::Serialize;
2931

3032
use crate::endian::{Endian, BigEndian, LittleEndian};
3133
use crate::error::Error;
@@ -99,7 +101,7 @@ impl IfdEntry {
99101
}
100102

101103
/// A TIFF/Exif field.
102-
#[derive(Debug, Clone, PartialEq)]
104+
#[derive(Debug, Clone, Deserialize, PartialEq, Serialize)]
103105
pub struct Field {
104106
/// The tag of this field.
105107
pub tag: Tag,
@@ -121,7 +123,7 @@ pub struct Field {
121123
/// assert_eq!(In::PRIMARY.index(), 0);
122124
/// assert_eq!(In::THUMBNAIL.index(), 1);
123125
/// ```
124-
#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
126+
#[derive(Debug, Copy, Clone, Deserialize, PartialEq, Eq, PartialOrd, Ord, Hash, Serialize)]
125127
pub struct In(pub u16);
126128

127129
impl In {

src/value.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,14 @@
2727
use std::fmt;
2828
use std::fmt::Write as _;
2929

30+
use serde::Deserialize;
31+
use serde::Serialize;
32+
3033
use crate::endian::Endian;
3134
use crate::error::Error;
3235

3336
/// A type and values of a TIFF/Exif field.
34-
#[derive(Clone, PartialEq)]
37+
#[derive(Clone, Deserialize, PartialEq, Serialize)]
3538
pub enum Value {
3639
/// Vector of 8-bit unsigned integers.
3740
Byte(Vec<u8>),
@@ -346,7 +349,7 @@ impl From<&DefaultValue> for Option<Value> {
346349
}
347350

348351
/// An unsigned rational number, which is a pair of 32-bit unsigned integers.
349-
#[derive(Copy, Clone, PartialEq)]
352+
#[derive(Copy, Clone, Deserialize, PartialEq, Serialize)]
350353
pub struct Rational { pub num: u32, pub denom: u32 }
351354

352355
impl Rational {
@@ -384,7 +387,7 @@ impl fmt::Display for Rational {
384387
}
385388

386389
/// A signed rational number, which is a pair of 32-bit signed integers.
387-
#[derive(Copy, Clone, PartialEq)]
390+
#[derive(Copy, Clone, Deserialize, PartialEq, Serialize)]
388391
pub struct SRational { pub num: i32, pub denom: i32 }
389392

390393
impl SRational {

0 commit comments

Comments
 (0)