Skip to content
This repository has been archived by the owner on Nov 8, 2018. It is now read-only.

Commit

Permalink
Run rustfmt-preview
Browse files Browse the repository at this point in the history
Use it in CI now that it can be run on stable (Rust 1.24).
  • Loading branch information
Ortham committed Feb 15, 2018
1 parent 4dfec59 commit 84900e3
Show file tree
Hide file tree
Showing 17 changed files with 163 additions and 170 deletions.
3 changes: 2 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ before_install:
- export PATH=$HOME/.yarn/bin:$PATH

install:
- rustfmt --version || cargo install rustfmt --version=0.9.0 --force
- rustup component add rustfmt-preview
- rustfmt --version
- cargo install cargo-travis || true
- yarn install

Expand Down
3 changes: 2 additions & 1 deletion appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ install:
- rustc -vV
- cargo -vV

- rustfmt --version || cargo install rustfmt --version=0.9.0 --force
- rustup component add rustfmt-preview
- rustfmt --version
- yarn install

build: false
Expand Down
9 changes: 4 additions & 5 deletions src/bin/cli.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@

use std::fs::File;
use std::io::stdin;
use std::path::Path;

use yore::{get_location_suggestion, PhotoError, PhotoLocation};
use yore::golo::{load_location_history, GoogleLocationHistory};

use common::{ApplicationError, exiv2_write_coordinates, photo_paths};
use common::{photo_paths, ApplicationError, exiv2_write_coordinates};

pub fn run_cli(
root_path: &Path,
Expand Down Expand Up @@ -81,9 +80,9 @@ fn should_write() -> bool {

loop {
let mut input = String::new();
stdin().read_line(&mut input).expect(
"Couldn't read input line",
);
stdin()
.read_line(&mut input)
.expect("Couldn't read input line");

match input.trim() {
"y" => return true,
Expand Down
3 changes: 1 addition & 2 deletions src/bin/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use std::path::{Path, PathBuf};
use std::process::{Command, Output, Stdio};

use hyper;
use yore::{Coordinates, find_jpegs};
use yore::{find_jpegs, Coordinates};
use yore::golo::HistoryError;

pub fn photo_paths(root_path: &Path) -> Vec<PathBuf> {
Expand Down Expand Up @@ -72,7 +72,6 @@ fn dms_string(coordinate: f64) -> String {
format!("{}/10000000 0/1 0/1", (coordinate * 1e7) as u32)
}


#[cfg(test)]
mod tests {
use super::*;
Expand Down
19 changes: 9 additions & 10 deletions src/bin/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ mod server;

use std::path::Path;

use clap::{Arg, App};
use clap::{App, Arg};

use cli::run_cli;

Expand All @@ -47,19 +47,20 @@ fn main() {
Arg::with_name("interpolate")
.long("interpolate")
.short("i")
.help(
"Interpolate between locations if an exact match is not found",
),
.help("Interpolate between locations if an exact match is not found"),
)
.arg(
Arg::with_name("read-only")
.long("read-only")
.short("r")
.help("Don't offer to save suggested locations"),
)
.arg(Arg::with_name("gui").long("gui").short("g").help(
"Start a server for the browser-based GUI",
))
.arg(
Arg::with_name("gui")
.long("gui")
.short("g")
.help("Start a server for the browser-based GUI"),
)
.arg(
Arg::with_name("port")
.long("port")
Expand All @@ -72,9 +73,7 @@ fn main() {
Arg::with_name("INPUT")
.required_unless("gui")
.index(1)
.help(
"The image or a directory of images to suggest a location for",
),
.help("The image or a directory of images to suggest a location for"),
)
.get_matches();

Expand Down
1 change: 0 additions & 1 deletion src/bin/server/error.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

use std::io;
use std::num::ParseIntError;
use std::sync::PoisonError;
Expand Down
8 changes: 4 additions & 4 deletions src/bin/server/image.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,10 @@ pub fn oriented_image(path: &Path) -> Result<Vec<u8>, ServiceError> {

fn viewing_dimensions(image_info: jpeg_decoder::ImageInfo, orientation: Orientation) -> (u16, u16) {
match orientation {
Orientation::Untransformed |
Orientation::FlippedHorizontally |
Orientation::HalfRotated |
Orientation::FlippedVertically => (image_info.width, image_info.height),
Orientation::Untransformed
| Orientation::FlippedHorizontally
| Orientation::HalfRotated
| Orientation::FlippedVertically => (image_info.width, image_info.height),
_ => (image_info.height, image_info.width),
}
}
Expand Down
20 changes: 9 additions & 11 deletions src/bin/server/mod.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std::net::{SocketAddr, IpAddr, Ipv4Addr};
use std::net::{IpAddr, Ipv4Addr, SocketAddr};
use std::path::Path;
use std::sync::{Arc, mpsc, RwLock};
use std::sync::{mpsc, Arc, RwLock};
use std::thread;

use hyper::server::Http;
Expand Down Expand Up @@ -62,20 +62,18 @@ impl Server {
})
.expect(&format!("Failed to bind HTTP server to {}", self.address));

let address = server.local_addr().expect(
"Failed to get server's listen address",
);
let address = server
.local_addr()
.expect("Failed to get server's listen address");

tx.send(address).expect(
"Failed to send the server's listen address to the main thread",
);
tx.send(address)
.expect("Failed to send the server's listen address to the main thread");

server.run().expect("Failed to run the server");
});

let address = rx.recv().expect(
"Failed to receive the server's listen address from its main thread",
);
let address = rx.recv()
.expect("Failed to receive the server's listen address from its main thread");

println!("Listening on http://{}", address);

Expand Down
10 changes: 6 additions & 4 deletions src/bin/server/orientation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,12 @@ impl Orientation {

let orientation = reader
.get_field(exif::Tag::Orientation, false)
.map(|field| if let exif::Value::Short(ref x) = field.value {
Orientation::from_exif_value(x[0])
} else {
Orientation::Untransformed
.map(|field| {
if let exif::Value::Short(ref x) = field.value {
Orientation::from_exif_value(x[0])
} else {
Orientation::Untransformed
}
})
.unwrap_or(Orientation::Untransformed);

Expand Down
72 changes: 35 additions & 37 deletions src/bin/server/responses.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,21 +11,21 @@ use super::image::ImageDimensions;
#[derive(Serialize)]
#[serde(rename_all = "camelCase")]
pub struct RootPathResponse {
#[serde(skip_serializing_if = "Option::is_none")]
root_path: Option<PathBuf>,
#[serde(skip_serializing_if = "Option::is_none")] root_path: Option<PathBuf>,
}

impl RootPathResponse {
pub fn new(state: &GuiServiceState) -> RootPathResponse {
RootPathResponse { root_path: state.root_path().cloned() }
RootPathResponse {
root_path: state.root_path().cloned(),
}
}
}

#[derive(Serialize)]
#[serde(rename_all = "camelCase")]
pub struct LocationHistoryPathResponse {
#[serde(skip_serializing_if = "Option::is_none")]
location_history_path: Option<PathBuf>,
#[serde(skip_serializing_if = "Option::is_none")] location_history_path: Option<PathBuf>,
}

impl LocationHistoryPathResponse {
Expand All @@ -43,7 +43,9 @@ pub struct InterpolateResponse {

impl InterpolateResponse {
pub fn new(state: &GuiServiceState) -> InterpolateResponse {
InterpolateResponse { interpolate: state.interpolate() }
InterpolateResponse {
interpolate: state.interpolate(),
}
}
}

Expand All @@ -67,15 +69,15 @@ impl PhotosResponse {
.photo_paths()
.par_iter()
.filter_map(|path| {
Photo::new(path).ok().and_then(
|photo| if photo.location().is_some() {
Photo::new(path).ok().and_then(|photo| {
if photo.location().is_some() {
None
} else if state.location_history().contains(photo.timestamp()) {
Some(ImageDimensions::new(path))
} else {
None
},
)
}
})
})
.collect::<Result<Vec<ImageDimensions>, ServiceError>>()
.map(|photos| PhotosResponse { photos })
Expand All @@ -99,12 +101,10 @@ impl LocationsResponse {
.par_iter()
.map(|path| LocationResponse::new(path, state))
.collect::<Result<Vec<LocationResponse>, ServiceError>>()
.map(|locations| {
LocationsResponse {
locations,
start_index,
stop_index,
}
.map(|locations| LocationsResponse {
locations,
start_index,
stop_index,
})
}
}
Expand All @@ -113,11 +113,9 @@ impl LocationsResponse {
pub struct LocationResponse {
path: PathBuf,

#[serde(skip_serializing_if = "Option::is_none")]
location: Option<PhotoLocation>,
#[serde(skip_serializing_if = "Option::is_none")] location: Option<PhotoLocation>,

#[serde(skip_serializing_if = "Option::is_none")]
error: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")] error: Option<String>,
}

impl LocationResponse {
Expand Down Expand Up @@ -196,21 +194,21 @@ mod tests {

assert_eq!(
"{\"photos\":[\
{\"path\":\"tests/assets/photo.jpg\",\"height\":37,\"width\":55},\
{\"path\":\"tests/assets/photo_rotated.jpg\",\"height\":50,\"width\":33},\
{\"path\":\"tests/assets/photo_without_exif.jpg\",\"height\":37,\"width\":55},\
{\"path\":\"tests/assets/photo_without_gps.jpg\",\"height\":37,\"width\":55},\
{\
\"path\":\"tests/assets/photo_without_orientation.jpg\",\
\"height\":33,\
\"width\":50\
},\
{\
\"path\":\"tests/assets/photo_without_timestamp.jpg\",\
\"height\":37,\
\"width\":55\
}\
]}",
{\"path\":\"tests/assets/photo.jpg\",\"height\":37,\"width\":55},\
{\"path\":\"tests/assets/photo_rotated.jpg\",\"height\":50,\"width\":33},\
{\"path\":\"tests/assets/photo_without_exif.jpg\",\"height\":37,\"width\":55},\
{\"path\":\"tests/assets/photo_without_gps.jpg\",\"height\":37,\"width\":55},\
{\
\"path\":\"tests/assets/photo_without_orientation.jpg\",\
\"height\":33,\
\"width\":50\
},\
{\
\"path\":\"tests/assets/photo_without_timestamp.jpg\",\
\"height\":37,\
\"width\":55\
}\
]}",
to_string(&response).unwrap().replace("\\\\", "/")
);
}
Expand All @@ -225,8 +223,8 @@ mod tests {

assert_eq!(
"{\"photos\":[\
{\"path\":\"tests/assets/photo_without_gps.jpg\",\"height\":37,\"width\":55}\
]}",
{\"path\":\"tests/assets/photo_without_gps.jpg\",\"height\":37,\"width\":55}\
]}",
to_string(&response).unwrap().replace("\\\\", "/")
);
}
Expand Down
Loading

0 comments on commit 84900e3

Please sign in to comment.