Skip to content

Commit c80e248

Browse files
committed
Format all code using rustfmt
1 parent 72f3bb5 commit c80e248

17 files changed

+828
-935
lines changed

rustfmt.toml

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
control_brace_style="ClosingNextLine"
2+
error_on_line_overflow=false
3+
fn_return_indent="WithWhereClause"
4+
imports_indent="Block"
5+
6+

src/exiftool.rs

+64-95
Original file line numberDiff line numberDiff line change
@@ -12,45 +12,36 @@ use std::process::Command;
1212

1313

1414
#[derive(Clone, Debug, PartialEq)]
15-
pub enum GpsStringParseError
16-
{
15+
pub enum GpsStringParseError {
1716
NumberParseError,
1817
InvalidDirection(String),
19-
BadFormat
18+
BadFormat,
2019
}
21-
impl std::convert::From<std::num::ParseFloatError> for GpsStringParseError
22-
{
23-
fn from(_: std::num::ParseFloatError) -> GpsStringParseError
24-
{
20+
impl std::convert::From<std::num::ParseFloatError> for GpsStringParseError {
21+
fn from(_: std::num::ParseFloatError) -> GpsStringParseError {
2522
GpsStringParseError::NumberParseError
2623
}
2724
}
28-
impl std::convert::From<std::num::ParseIntError> for GpsStringParseError
29-
{
30-
fn from(_: std::num::ParseIntError) -> GpsStringParseError
31-
{
25+
impl std::convert::From<std::num::ParseIntError> for GpsStringParseError {
26+
fn from(_: std::num::ParseIntError) -> GpsStringParseError {
3227
GpsStringParseError::NumberParseError
3328
}
3429
}
3530

3631

3732
#[derive(PartialEq, Debug)]
38-
pub enum CardinalDirection
39-
{
33+
pub enum CardinalDirection {
4034
East,
4135
West,
4236
North,
43-
South
37+
South,
4438
}
4539

46-
impl std::str::FromStr for CardinalDirection
47-
{
40+
impl std::str::FromStr for CardinalDirection {
4841
type Err = GpsStringParseError;
4942

50-
fn from_str(name: &str) -> Result<CardinalDirection, GpsStringParseError>
51-
{
52-
match name
53-
{
43+
fn from_str(name: &str) -> Result<CardinalDirection, GpsStringParseError> {
44+
match name {
5445
"N" => Ok(CardinalDirection::North),
5546
"S" => Ok(CardinalDirection::South),
5647
"W" => Ok(CardinalDirection::West),
@@ -61,124 +52,111 @@ impl std::str::FromStr for CardinalDirection
6152
}
6253

6354
#[derive(PartialEq, Debug)]
64-
pub struct GpsCoordinate
65-
{
55+
pub struct GpsCoordinate {
6656
degrees: i16,
6757
minutes: i16,
6858
seconds: f32,
69-
direction: CardinalDirection
59+
direction: CardinalDirection,
7060
}
7161

72-
impl GpsCoordinate
73-
{
74-
75-
pub fn new(degrees: i16, minutes: i16, seconds: f32, direction: CardinalDirection) -> GpsCoordinate
76-
{
77-
GpsCoordinate{
62+
impl GpsCoordinate {
63+
pub fn new(
64+
degrees: i16,
65+
minutes: i16,
66+
seconds: f32,
67+
direction: CardinalDirection,
68+
) -> GpsCoordinate {
69+
GpsCoordinate {
7870
degrees: degrees,
7971
minutes: minutes,
8072
seconds: seconds,
81-
direction: direction
73+
direction: direction,
8274
}
8375
}
8476
}
8577

86-
impl std::str::FromStr for GpsCoordinate
87-
{
78+
impl std::str::FromStr for GpsCoordinate {
8879
type Err = GpsStringParseError;
8980

90-
fn from_str(string: &str) -> Result<GpsCoordinate, Self::Err>
91-
{
81+
fn from_str(string: &str) -> Result<GpsCoordinate, Self::Err> {
9282
lazy_static! {
9383
static ref RE: Regex = Regex::new("(\\d*) deg (\\d*)' (\\d*.?\\d*)\" ([NEWS])").unwrap();
9484
}
9585

96-
match RE.captures_iter(string).next()
97-
{
98-
Some(val) => Ok(GpsCoordinate{
86+
match RE.captures_iter(string).next() {
87+
Some(val) => Ok(GpsCoordinate {
9988
degrees: val[1].parse()?,
10089
minutes: val[2].parse()?,
10190
seconds: val[3].parse()?,
102-
direction: CardinalDirection::from_str(&val[4])?
91+
direction: CardinalDirection::from_str(&val[4])?,
10392
}),
104-
None => Err(GpsStringParseError::BadFormat)
93+
None => Err(GpsStringParseError::BadFormat),
10594
}
10695
}
10796
}
10897

10998
/**
11099
A GPS location
111100
*/
112-
pub struct Location
113-
{
101+
pub struct Location {
114102
longitude: GpsCoordinate,
115-
latitude: GpsCoordinate
103+
latitude: GpsCoordinate,
116104
}
117-
impl Location
118-
{
119-
pub fn new(longitude: GpsCoordinate, latitude: GpsCoordinate) -> Location
120-
{
105+
impl Location {
106+
pub fn new(longitude: GpsCoordinate, latitude: GpsCoordinate) -> Location {
121107
Location {
122108
longitude: longitude,
123-
latitude: latitude
109+
latitude: latitude,
124110
}
125111
}
126112
}
127113

128-
pub struct ExifData
129-
{
130-
tags: HashMap<String, String>
114+
pub struct ExifData {
115+
tags: HashMap<String, String>,
131116
}
132117

133118
#[derive(Debug)]
134-
pub enum ExifError
135-
{
119+
pub enum ExifError {
136120
InvalidGpsCoordinate(GpsStringParseError),
137121
NoSuchTag(String),
138122
MalformedDatetime(String),
139123
IoError(std::io::Error),
140-
MalformedUtf8(std::string::FromUtf8Error)
124+
MalformedUtf8(std::string::FromUtf8Error),
141125
}
142-
impl std::convert::From<std::io::Error> for ExifError
143-
{
144-
fn from(e: std::io::Error) -> ExifError
145-
{
126+
impl std::convert::From<std::io::Error> for ExifError {
127+
fn from(e: std::io::Error) -> ExifError {
146128
ExifError::IoError(e)
147129
}
148130
}
149-
impl std::convert::From<std::string::FromUtf8Error> for ExifError
150-
{
151-
fn from(e: std::string::FromUtf8Error) -> ExifError
152-
{
131+
impl std::convert::From<std::string::FromUtf8Error> for ExifError {
132+
fn from(e: std::string::FromUtf8Error) -> ExifError {
153133
ExifError::MalformedUtf8(e)
154134
}
155135
}
156136

157137

158138

159-
impl ExifData
160-
{
161-
pub fn from_exiftool_string(data: &str) -> Result<ExifData, ExifError>
162-
{
163-
let mut result = ExifData{
164-
tags: HashMap::new()
139+
impl ExifData {
140+
pub fn from_exiftool_string(data: &str) -> Result<ExifData, ExifError> {
141+
let mut result = ExifData {
142+
tags: HashMap::new(),
165143
};
166144

167145
lazy_static! {
168146
static ref DATA_REGEX: Regex = Regex::new(r"(.*\b)\s*: (.*)").unwrap();
169147
}
170148

171-
for matches in DATA_REGEX.captures_iter(data)
172-
{
149+
for matches in DATA_REGEX.captures_iter(data) {
173150
//TODO: Handle erros here
174-
result.tags.insert(String::from(&matches[1]), String::from(&matches[2]));
151+
result
152+
.tags
153+
.insert(String::from(&matches[1]), String::from(&matches[2]));
175154
}
176155

177156
Ok(result)
178157
}
179158

180-
pub fn from_file(file: &str) -> Result<ExifData, ExifError>
181-
{
159+
pub fn from_file(file: &str) -> Result<ExifData, ExifError> {
182160
let mut cmd = Command::new("exiftool");
183161
cmd.arg(file);
184162

@@ -191,45 +169,37 @@ impl ExifData
191169
Self::from_exiftool_string(&command_output)
192170
}
193171

194-
pub fn get_tag(&self, name: &str) -> Option<&str>
195-
{
196-
match self.tags.get(name)
197-
{
172+
pub fn get_tag(&self, name: &str) -> Option<&str> {
173+
match self.tags.get(name) {
198174
Some(tag) => Some(tag),
199-
None => None
175+
None => None,
200176
}
201177
}
202178

203-
pub fn get_creation_date(&self) -> Result<chrono::DateTime<chrono::UTC>, ExifError>
204-
{
179+
pub fn get_creation_date(&self) -> Result<chrono::DateTime<chrono::UTC>, ExifError> {
205180
let target_tag = "Create Date";
206-
match self.get_tag(target_tag)
207-
{
208-
Some(date_string) =>
209-
{
181+
match self.get_tag(target_tag) {
182+
Some(date_string) => {
210183
let parsed = chrono::UTC.datetime_from_str(date_string, "%Y:%m:%d %H:%M:%S");
211184

212-
match parsed
213-
{
185+
match parsed {
214186
Ok(result) => Ok(result),
215-
_ => Err(ExifError::MalformedDatetime(String::from(date_string)))
187+
_ => Err(ExifError::MalformedDatetime(String::from(date_string))),
216188
}
217189
}
218-
None => Err(ExifError::NoSuchTag(String::from(target_tag)))
190+
None => Err(ExifError::NoSuchTag(String::from(target_tag))),
219191
}
220192
}
221193
}
222194

223195

224196
#[cfg(test)]
225-
mod exif_data_tests
226-
{
197+
mod exif_data_tests {
227198
use std::str::FromStr;
228199
use super::*;
229200

230201
#[test]
231-
fn well_formed_file()
232-
{
202+
fn well_formed_file() {
233203
let file_content = include_str!("../test/files/exif1.txt");
234204

235205
let data = ExifData::from_exiftool_string(file_content).unwrap();
@@ -244,14 +214,13 @@ mod exif_data_tests
244214
}
245215

246216
#[test]
247-
fn gps_coordinate_test()
248-
{
217+
fn gps_coordinate_test() {
249218
assert_eq!(
250-
GpsCoordinate::from_str("58 deg 28' 5.45\" N").unwrap(),
219+
GpsCoordinate::from_str("58 deg 28' 5.45\" N").unwrap(),
251220
GpsCoordinate::new(58, 28, 5.45, CardinalDirection::North)
252221
);
253222
assert_eq!(
254-
GpsCoordinate::from_str("58 deg 28' 5.45\" S").unwrap(),
223+
GpsCoordinate::from_str("58 deg 28' 5.45\" S").unwrap(),
255224
GpsCoordinate::new(58, 28, 5.45, CardinalDirection::South)
256225
);
257226
}

0 commit comments

Comments
 (0)