Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rustfmt, clippy #4

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1,281 changes: 888 additions & 393 deletions src/exif.rs

Large diffs are not rendered by default.

41 changes: 27 additions & 14 deletions src/exifpost.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,24 @@
use super::types::{ExifEntry, ExifTag, TagValue};

/// Find a tag of given type
fn other_tag<'a>(tag: ExifTag, entries1: &'a [ExifEntry], entries2: &'a [ExifEntry]) -> Option<&'a ExifEntry> {
entries1.iter().find(|entry| entry.tag == tag)
.or_else(|| entries2.iter().find(|entry| entry.tag == tag))
fn other_tag<'a>(
tag: ExifTag,
entries1: &'a [ExifEntry],
entries2: &'a [ExifEntry],
) -> Option<&'a ExifEntry> {
entries1
.iter()
.find(|entry| entry.tag == tag)
.or_else(|| entries2.iter().find(|entry| entry.tag == tag))
}

/// Does postprocessing in tags that depend on other tags to have a complete interpretation
/// e.g. when the unit of a tag is annotated on another tag
pub(crate) fn exif_postprocessing(entry: &mut ExifEntry, entries1: &[ExifEntry], entries2: &[ExifEntry]) {
pub(crate) fn exif_postprocessing(
entry: &mut ExifEntry,
entries1: &[ExifEntry],
entries2: &[ExifEntry],
) {
match entry.tag {
ExifTag::XResolution | ExifTag::YResolution => {
if let Some(f) = other_tag(ExifTag::ResolutionUnit, entries1, entries2) {
Expand All @@ -17,7 +27,7 @@ pub(crate) fn exif_postprocessing(entry: &mut ExifEntry, entries1: &[ExifEntry],
v.push_str(" pixels per ");
v.push_str(&f.value_more_readable);
}
},
}

ExifTag::FocalPlaneXResolution | ExifTag::FocalPlaneYResolution => {
if let Some(f) = other_tag(ExifTag::FocalPlaneResolutionUnit, entries1, entries2) {
Expand All @@ -26,23 +36,23 @@ pub(crate) fn exif_postprocessing(entry: &mut ExifEntry, entries1: &[ExifEntry],
v.push_str(" pixels per ");
v.push_str(&f.value_more_readable);
}
},
}

ExifTag::GPSLatitude => {
if let Some(f) = other_tag(ExifTag::GPSLatitudeRef, entries1, entries2) {
let v = entry.value_more_readable.to_mut();
v.push(' ');
v.push_str(&f.value_more_readable);
}
},
}

ExifTag::GPSLongitude => {
if let Some(f) = other_tag(ExifTag::GPSLongitudeRef, entries1, entries2) {
let v = entry.value_more_readable.to_mut();
v.push(' ');
v.push_str(&f.value_more_readable);
}
},
}

ExifTag::GPSAltitude => {
if let Some(f) = other_tag(ExifTag::GPSAltitudeRef, entries1, entries2) {
Expand All @@ -52,26 +62,29 @@ pub(crate) fn exif_postprocessing(entry: &mut ExifEntry, entries1: &[ExifEntry],
};

if altref != 0 {
entry.value_more_readable.to_mut().push_str(" below sea level");
entry
.value_more_readable
.to_mut()
.push_str(" below sea level");
}
}
},
}

ExifTag::GPSDestLatitude => {
if let Some(f) = other_tag(ExifTag::GPSDestLatitudeRef, entries1, entries2) {
let v = entry.value_more_readable.to_mut();
v.push(' ');
v.push_str(&f.value_more_readable);
}
},
}

ExifTag::GPSDestLongitude => {
if let Some(f) = other_tag(ExifTag::GPSDestLongitudeRef, entries1, entries2) {
let v = entry.value_more_readable.to_mut();
v.push(' ');
v.push_str(&f.value_more_readable);
}
},
}

ExifTag::GPSDestDistance => {
if let Some(f) = other_tag(ExifTag::GPSDestDistanceRef, entries1, entries2) {
Expand All @@ -80,7 +93,7 @@ pub(crate) fn exif_postprocessing(entry: &mut ExifEntry, entries1: &[ExifEntry],
v.push(' ');
v.push_str(&f.value_more_readable);
}
},
}

ExifTag::GPSSpeed => {
if let Some(f) = other_tag(ExifTag::GPSSpeedRef, entries1, entries2) {
Expand All @@ -89,7 +102,7 @@ pub(crate) fn exif_postprocessing(entry: &mut ExifEntry, entries1: &[ExifEntry],
v.push(' ');
v.push_str(&f.value_more_readable);
}
},
}
_ => (),
}
}
Loading