From f2b73449405cb6115d2ca3c68a4fee144a1c4f1f Mon Sep 17 00:00:00 2001 From: Dustin Carlino Date: Thu, 10 May 2018 16:12:16 -0700 Subject: [PATCH] using new rust 1.26 match stuff, and fmt --- editor/src/main.rs | 4 ++-- editor/src/plugins/search.rs | 4 ++-- editor/src/plugins/selection.rs | 4 ++-- editor/src/plugins/snake.rs | 2 +- editor/src/plugins/stop_sign_editor.rs | 8 ++++---- editor/src/plugins/traffic_signal_editor.rs | 12 ++++++------ editor/src/plugins/turn_colors.rs | 2 +- editor/src/render/map.rs | 2 +- editor/src/render/road.rs | 2 +- editor/src/render/turn.rs | 2 +- editor/src/ui.rs | 4 ++-- ezgui/src/canvas.rs | 4 ++-- map_model/src/lib.rs | 2 +- rgrep.sh | 2 +- sim/src/straw_intersections.rs | 6 +++--- sim/src/straw_model.rs | 11 ++++++----- 16 files changed, 36 insertions(+), 35 deletions(-) diff --git a/editor/src/main.rs b/editor/src/main.rs index 7286396e71..b5e2eb4168 100644 --- a/editor/src/main.rs +++ b/editor/src/main.rs @@ -31,12 +31,12 @@ extern crate structopt; extern crate svg; extern crate vecmath; +use ezgui::input::UserInput; use glutin_window::GlutinWindow; +use opengl_graphics::{Filter, GlGraphics, GlyphCache, OpenGL, TextureSettings}; use piston::event_loop::{EventLoop, EventSettings, Events}; use piston::input::RenderEvent; use piston::window::{Window, WindowSettings}; -use opengl_graphics::{Filter, GlGraphics, GlyphCache, OpenGL, TextureSettings}; -use ezgui::input::UserInput; use structopt::StructOpt; mod animation; diff --git a/editor/src/plugins/search.rs b/editor/src/plugins/search.rs index bf2d482d16..a6c3e7ae6e 100644 --- a/editor/src/plugins/search.rs +++ b/editor/src/plugins/search.rs @@ -35,7 +35,7 @@ impl SearchState { } fn choose_color(&self, osm_tags: &[String]) -> Option { - if let SearchState::FilterOSM(ref filter) = *self { + if let SearchState::FilterOSM(filter) = self { for tag in osm_tags { if tag.contains(filter) { return Some(render::SEARCH_RESULT_COLOR); @@ -78,7 +78,7 @@ impl SearchState { } pub fn draw(&self, canvas: &Canvas, g: &mut GfxCtx) { - if let SearchState::EnteringSearch(ref text_box) = *self { + if let SearchState::EnteringSearch(text_box) = self { canvas.draw_osd_notification(g, &vec![text_box.line.clone()]); // TODO draw the cursor } diff --git a/editor/src/plugins/selection.rs b/editor/src/plugins/selection.rs index b0bff4a2b5..7710fb98f3 100644 --- a/editor/src/plugins/selection.rs +++ b/editor/src/plugins/selection.rs @@ -13,13 +13,13 @@ // limitations under the License. use animation; +use control::ControlMap; use ezgui::canvas::{Canvas, GfxCtx}; use ezgui::input::UserInput; use geom; use graphics::types::Color; use map_model; use map_model::{BuildingID, IntersectionID, Map, RoadID, TurnID}; -use control::ControlMap; use piston::input::{Button, Key, ReleaseEvent}; use render; use sim::CarID; @@ -156,7 +156,7 @@ impl SelectionState { match *self { SelectionState::Empty | SelectionState::SelectedTurn(_) => {} SelectionState::SelectedIntersection(id) => { - if let Some(ref signal) = control_map.traffic_signals.get(&id) { + if let Some(signal) = control_map.traffic_signals.get(&id) { let (cycle, _) = signal.current_cycle_and_remaining_time(sim.time.as_time()); for t in &cycle.turns { draw_map.get_t(*t).draw_full(g, render::TURN_COLOR); diff --git a/editor/src/plugins/snake.rs b/editor/src/plugins/snake.rs index 319d9d58ef..8517224ac6 100644 --- a/editor/src/plugins/snake.rs +++ b/editor/src/plugins/snake.rs @@ -16,8 +16,8 @@ extern crate map_model; use animation; use ezgui::canvas::{Canvas, GfxCtx}; -use graphics::types::Color; use ezgui::input::UserInput; +use graphics::types::Color; use map_model::{Map, Pt2D, Road, RoadID, TurnID}; use piston::input::{Key, UpdateEvent}; use piston::window::Size; diff --git a/editor/src/plugins/stop_sign_editor.rs b/editor/src/plugins/stop_sign_editor.rs index 4cf51e9759..b3f7a043fb 100644 --- a/editor/src/plugins/stop_sign_editor.rs +++ b/editor/src/plugins/stop_sign_editor.rs @@ -14,16 +14,16 @@ extern crate map_model; +use control::ControlMap; use control::stop_signs::TurnPriority; use ezgui::canvas; +use ezgui::input::UserInput; use geom::GeomMap; use graphics::types::Color; -use map_model::{Map, Turn}; -use plugins::selection::SelectionState; -use control::ControlMap; use map_model::IntersectionID; -use ezgui::input::UserInput; +use map_model::{Map, Turn}; use piston::input::Key; +use plugins::selection::SelectionState; pub struct StopSignEditor { i: IntersectionID, diff --git a/editor/src/plugins/traffic_signal_editor.rs b/editor/src/plugins/traffic_signal_editor.rs index 6a32ce619d..7363b5b7fd 100644 --- a/editor/src/plugins/traffic_signal_editor.rs +++ b/editor/src/plugins/traffic_signal_editor.rs @@ -16,15 +16,15 @@ extern crate map_model; -use ezgui::canvas; -use geom::GeomMap; -use map_model::Map; -use graphics::types::Color; -use plugins::selection::SelectionState; use control::ControlMap; -use map_model::{IntersectionID, Turn}; +use ezgui::canvas; use ezgui::input::UserInput; +use geom::GeomMap; +use graphics::types::Color; +use map_model::Map; +use map_model::{IntersectionID, Turn}; use piston::input::Key; +use plugins::selection::SelectionState; pub struct TrafficSignalEditor { i: IntersectionID, diff --git a/editor/src/plugins/turn_colors.rs b/editor/src/plugins/turn_colors.rs index 3bc70944f8..c278208f68 100644 --- a/editor/src/plugins/turn_colors.rs +++ b/editor/src/plugins/turn_colors.rs @@ -16,9 +16,9 @@ extern crate map_model; +use control::ControlMap; use graphics::types::Color; use map_model::{Turn, TurnID}; -use control::ControlMap; use std::collections::HashMap; const CYCLE_COLORS: [Color; 8] = [ diff --git a/editor/src/render/map.rs b/editor/src/render/map.rs index 22d1c30871..fc499454f0 100644 --- a/editor/src/render/map.rs +++ b/editor/src/render/map.rs @@ -17,8 +17,8 @@ extern crate map_model; use aabb_quadtree::QuadTree; use aabb_quadtree::geom::{Point, Rect}; -use geom::geometry; use geom::GeomMap; +use geom::geometry; use map_model::{Bounds, BuildingID, IntersectionID, Map, ParcelID, Pt2D, RoadID, TurnID}; use render::building::DrawBuilding; use render::intersection::DrawIntersection; diff --git a/editor/src/render/road.rs b/editor/src/render/road.rs index 384b4a83c4..4dae2aae03 100644 --- a/editor/src/render/road.rs +++ b/editor/src/render/road.rs @@ -22,8 +22,8 @@ use geom::geometry; use graphics; use graphics::math::Vec2d; use graphics::types::Color; -use render::{BRIGHT_DEBUG_COLOR, DEBUG_COLOR, PARCEL_BOUNDARY_THICKNESS, ROAD_ORIENTATION_COLOR}; use map_model::{Bounds, Pt2D, RoadID}; +use render::{BRIGHT_DEBUG_COLOR, DEBUG_COLOR, PARCEL_BOUNDARY_THICKNESS, ROAD_ORIENTATION_COLOR}; use std::f64; use svg; diff --git a/editor/src/render/turn.rs b/editor/src/render/turn.rs index f49a06af22..56ea4dd75b 100644 --- a/editor/src/render/turn.rs +++ b/editor/src/render/turn.rs @@ -18,8 +18,8 @@ extern crate map_model; use aabb_quadtree::geom::Rect; use ezgui::canvas::GfxCtx; use geom; -use geom::geometry; use geom::GeomMap; +use geom::geometry; use graphics; use graphics::math::Vec2d; use graphics::types::Color; diff --git a/editor/src/ui.rs b/editor/src/ui.rs index 41d8b08b9c..9e886e4950 100644 --- a/editor/src/ui.rs +++ b/editor/src/ui.rs @@ -17,13 +17,13 @@ extern crate map_model; use animation; +use control::ControlMap; use ezgui::ToggleableLayer; use ezgui::canvas; use ezgui::canvas::{Canvas, GfxCtx}; +use ezgui::input::UserInput; use geom; use graphics::types::Color; -use control::ControlMap; -use ezgui::input::UserInput; use piston::input::{Key, MouseCursorEvent}; use piston::window::Size; use plugins::classification::OsmClassifier; diff --git a/ezgui/src/canvas.rs b/ezgui/src/canvas.rs index f101563d08..c569115514 100644 --- a/ezgui/src/canvas.rs +++ b/ezgui/src/canvas.rs @@ -14,13 +14,13 @@ use aabb_quadtree::geom::{Point, Rect}; use graphics; -use graphics::{Context, Image, Transformed}; use graphics::character::CharacterCache; use graphics::types::Color; +use graphics::{Context, Image, Transformed}; +use opengl_graphics::{GlGraphics, Texture}; use piston::input::{Button, Event, Key, MouseButton, MouseCursorEvent, MouseScrollEvent, PressEvent, ReleaseEvent}; use piston::window::Size; -use opengl_graphics::{GlGraphics, Texture}; //pub const WHITE: Color = [1.0, 1.0, 1.0, 1.0]; pub const BLACK: Color = [0.0, 0.0, 0.0, 1.0]; diff --git a/map_model/src/lib.rs b/map_model/src/lib.rs index 9fdc0c91e4..d122902395 100644 --- a/map_model/src/lib.rs +++ b/map_model/src/lib.rs @@ -19,8 +19,8 @@ extern crate serde; extern crate serde_derive; use ordered_float::NotNaN; -use protobuf::{CodedInputStream, CodedOutputStream, Message}; use protobuf::error::ProtobufError; +use protobuf::{CodedInputStream, CodedOutputStream, Message}; use std::collections::HashMap; use std::f64; use std::fs::File; diff --git a/rgrep.sh b/rgrep.sh index ef3bb06bf7..a6d71ac64d 100755 --- a/rgrep.sh +++ b/rgrep.sh @@ -1,3 +1,3 @@ #!/bin/bash -grep -R --exclude-dir=.git --exclude-dir=target --exclude-dir=data --exclude=Cargo.lock $@ +grep -R --exclude-dir=.git --exclude-dir=target --exclude-dir=data --exclude=Cargo.lock "$@" diff --git a/sim/src/straw_intersections.rs b/sim/src/straw_intersections.rs index 0c768e02c6..dcf0995074 100644 --- a/sim/src/straw_intersections.rs +++ b/sim/src/straw_intersections.rs @@ -54,9 +54,9 @@ impl IntersectionPolicy { } pub fn on_enter(&self, car: CarID) { - match *self { - IntersectionPolicy::StopSignPolicy(ref p) => p.on_enter(car), - IntersectionPolicy::TrafficSignalPolicy(ref p) => p.on_enter(car), + match self { + IntersectionPolicy::StopSignPolicy(p) => p.on_enter(car), + IntersectionPolicy::TrafficSignalPolicy(p) => p.on_enter(car), } } pub fn on_exit(&mut self, car: CarID) { diff --git a/sim/src/straw_model.rs b/sim/src/straw_model.rs index 7d566186cb..cea1de9e0e 100644 --- a/sim/src/straw_model.rs +++ b/sim/src/straw_model.rs @@ -286,7 +286,8 @@ impl SimQueue { pub struct Sim { // This is slightly dangerous, but since we'll be using comparisons based on savestating (which // captures the RNG), this should be OK for now. - #[derivative(PartialEq = "ignore")] rng: XorShiftRng, + #[derivative(PartialEq = "ignore")] + rng: XorShiftRng, // TODO investigate slot map-like structures for performance // Using BTreeMap instead of HashMap so iteration is deterministic. Should be able to relax // this later after step() doesnt need a RNG. @@ -309,9 +310,9 @@ impl Sim { let mut intersections: Vec = Vec::new(); for i in map.all_intersections() { if i.has_traffic_signal { - intersections.push(IntersectionPolicy::TrafficSignalPolicy( - TrafficSignal::new(i.id), - )); + intersections.push(IntersectionPolicy::TrafficSignalPolicy(TrafficSignal::new( + i.id, + ))); } else { intersections.push(IntersectionPolicy::StopSignPolicy(StopSign::new(i.id))); } @@ -427,7 +428,7 @@ impl Sim { // It might make more sense to push the conflict resolution down to SimQueue? // TODO should shuffle deterministically here, to be more fair let mut new_car_entered_this_step = HashSet::new(); - for &(ref id, ref act) in &requested_moves { + for (id, act) in &requested_moves { match *act { Action::Vanish => { self.cars.remove(&id);