From da8310b0764a6a0f5ebdaad7e3ed8ad1162b1249 Mon Sep 17 00:00:00 2001 From: Alexandre Bury Date: Mon, 22 Jan 2018 14:37:27 -0800 Subject: [PATCH] Rustfmt --- examples/markup.rs | 7 +++---- examples/terminal_default.rs | 1 - src/backend/blt.rs | 5 +---- src/backend/curses/n.rs | 14 +++++--------- src/backend/curses/pan.rs | 14 +++++--------- src/cursive.rs | 7 ++----- src/printer.rs | 14 +++----------- src/utils/lines/spans/prefix.rs | 4 +--- src/utils/lines/spans/row.rs | 3 +-- src/utils/markup/mod.rs | 1 - src/vec.rs | 2 +- src/view/boxable.rs | 4 +--- src/view/mod.rs | 1 - src/view/position.rs | 10 ++-------- src/view/view_wrapper.rs | 8 ++------ src/views/box_view.rs | 4 +--- src/views/checkbox.rs | 6 ++---- src/views/dialog.rs | 16 ++++++++-------- src/views/edit_view.rs | 9 +++------ src/views/id_view.rs | 4 +--- src/views/linear_layout.rs | 17 ++++++----------- src/views/list_view.rs | 14 ++++---------- src/views/menubar.rs | 5 +---- src/views/progress_bar.rs | 6 ++---- src/views/radio.rs | 11 +++-------- src/views/stack_view.rs | 18 +++++++----------- 26 files changed, 65 insertions(+), 140 deletions(-) diff --git a/examples/markup.rs b/examples/markup.rs index ab2ee02..873dd0e 100644 --- a/examples/markup.rs +++ b/examples/markup.rs @@ -1,13 +1,12 @@ extern crate cursive; use cursive::Cursive; -use cursive::views::{Dialog, TextView}; - -use cursive::theme::Color; use cursive::theme::BaseColor; -use cursive::theme::Style; +use cursive::theme::Color; use cursive::theme::Effect; +use cursive::theme::Style; use cursive::utils::markup::StyledString; +use cursive::views::{Dialog, TextView}; fn main() { let mut siv = Cursive::new(); diff --git a/examples/terminal_default.rs b/examples/terminal_default.rs index af1fb42..3531d24 100644 --- a/examples/terminal_default.rs +++ b/examples/terminal_default.rs @@ -17,7 +17,6 @@ fn main() { // We can quit by pressing `q` siv.add_global_callback('q', Cursive::quit); - siv.add_layer(TextView::new( "Hello World with default terminal background color!\n\ Press q to quit the application.", diff --git a/src/backend/blt.rs b/src/backend/blt.rs index 05b49fa..f3a47cc 100644 --- a/src/backend/blt.rs +++ b/src/backend/blt.rs @@ -22,10 +22,7 @@ pub struct Concrete { impl Concrete { fn blt_keycode_to_ev( - &mut self, - kc: KeyCode, - shift: bool, - ctrl: bool, + &mut self, kc: KeyCode, shift: bool, ctrl: bool ) -> Event { match kc { KeyCode::F1 diff --git a/src/backend/curses/n.rs b/src/backend/curses/n.rs index c6189bc..66ba074 100644 --- a/src/backend/curses/n.rs +++ b/src/backend/curses/n.rs @@ -24,9 +24,7 @@ pub struct Concrete { impl Concrete { /// Save a new color pair. fn insert_color( - &self, - pairs: &mut HashMap, - pair: ColorPair, + &self, pairs: &mut HashMap, pair: ColorPair ) -> i16 { let n = 1 + pairs.len() as i16; let target = if ncurses::COLOR_PAIRS() > i32::from(n) { @@ -91,12 +89,10 @@ impl Concrete { | ncurses::BUTTON_CTRL) as mmask_t; - let make_event = |event| { - Event::Mouse { - offset: Vec2::zero(), - position: Vec2::new(mevent.x as usize, mevent.y as usize), - event: event, - } + let make_event = |event| Event::Mouse { + offset: Vec2::zero(), + position: Vec2::new(mevent.x as usize, mevent.y as usize), + event: event, }; if mevent.bstate == ncurses::REPORT_MOUSE_POSITION as mmask_t { diff --git a/src/backend/curses/pan.rs b/src/backend/curses/pan.rs index 817e294..6567f7a 100644 --- a/src/backend/curses/pan.rs +++ b/src/backend/curses/pan.rs @@ -22,9 +22,7 @@ pub struct Concrete { impl Concrete { /// Save a new color pair. fn insert_color( - &self, - pairs: &mut HashMap, - pair: ColorPair, + &self, pairs: &mut HashMap, pair: ColorPair ) -> i32 { let n = 1 + pairs.len() as i32; @@ -82,12 +80,10 @@ impl Concrete { mevent.bstate &= !(pancurses::BUTTON_SHIFT | pancurses::BUTTON_ALT | pancurses::BUTTON_CTRL) as mmask_t; - let make_event = |event| { - Event::Mouse { - offset: Vec2::zero(), - position: Vec2::new(mevent.x as usize, mevent.y as usize), - event: event, - } + let make_event = |event| Event::Mouse { + offset: Vec2::zero(), + position: Vec2::new(mevent.x as usize, mevent.y as usize), + event: event, }; if mevent.bstate == pancurses::REPORT_MOUSE_POSITION as mmask_t { diff --git a/src/cursive.rs b/src/cursive.rs index 7cb3286..28cc19a 100644 --- a/src/cursive.rs +++ b/src/cursive.rs @@ -175,8 +175,7 @@ impl Cursive { /// /// `filename` must point to a valid toml file. pub fn load_theme_file>( - &mut self, - filename: P, + &mut self, filename: P ) -> Result<(), theme::Error> { self.set_theme(try!(theme::load_theme_file(filename))); Ok(()) @@ -281,9 +280,7 @@ impl Cursive { /// # } /// ``` pub fn call_on( - &mut self, - sel: &view::Selector, - callback: F, + &mut self, sel: &view::Selector, callback: F ) -> Option where V: View + Any, diff --git a/src/printer.rs b/src/printer.rs index 18d3f84..f55a4ee 100644 --- a/src/printer.rs +++ b/src/printer.rs @@ -33,9 +33,7 @@ impl<'a> Printer<'a> { /// But nobody needs to know that. #[doc(hidden)] pub fn new>( - size: T, - theme: &'a Theme, - backend: &'a backend::Concrete, + size: T, theme: &'a Theme, backend: &'a backend::Concrete ) -> Self { Printer { offset: Vec2::zero(), @@ -204,10 +202,7 @@ impl<'a> Printer<'a> { /// printer.print_box((0,0), (6,4), false); /// ``` pub fn print_box, S: Into>( - &self, - start: T, - size: S, - invert: bool, + &self, start: T, size: S, invert: bool ) { self.new.set(false); @@ -304,10 +299,7 @@ impl<'a> Printer<'a> { /// Returns a printer on a subset of this one's area. pub fn sub_printer, T: Into>( - &'a self, - offset: S, - size: T, - focused: bool, + &'a self, offset: S, size: T, focused: bool ) -> Printer<'a> { let size = size.into(); let offset = offset.into().or_min(self.size); diff --git a/src/utils/lines/spans/prefix.rs b/src/utils/lines/spans/prefix.rs index da86c3b..f713dc2 100644 --- a/src/utils/lines/spans/prefix.rs +++ b/src/utils/lines/spans/prefix.rs @@ -3,9 +3,7 @@ use std::iter::Peekable; /// Concatenates chunks as long as they fit in the given width. pub fn prefix<'a, I>( - tokens: &mut Peekable, - width: usize, - offset: &mut ChunkPart, + tokens: &mut Peekable, width: usize, offset: &mut ChunkPart ) -> Vec> where I: Iterator>, diff --git a/src/utils/lines/spans/row.rs b/src/utils/lines/spans/row.rs index b9cfbb7..64d3a94 100644 --- a/src/utils/lines/spans/row.rs +++ b/src/utils/lines/spans/row.rs @@ -13,8 +13,7 @@ pub struct Row { impl Row { /// Resolve the row indices into string slices and attributes. pub fn resolve<'a, T>( - &self, - source: &'a SpannedString, + &self, source: &'a SpannedString ) -> Vec> { self.segments .iter() diff --git a/src/utils/markup/mod.rs b/src/utils/markup/mod.rs index 14ebab3..8f05e78 100644 --- a/src/utils/markup/mod.rs +++ b/src/utils/markup/mod.rs @@ -6,7 +6,6 @@ pub mod markdown; use theme::Style; - use utils::span::{IndexedSpan, Span, SpannedString}; /// A parsed string with markup style. diff --git a/src/vec.rs b/src/vec.rs index 3168e32..9e5e605 100644 --- a/src/vec.rs +++ b/src/vec.rs @@ -284,7 +284,7 @@ impl From<((i32, i32), (i32, i32))> for Vec4 { } impl From<((usize, usize), (usize, usize))> for Vec4 { fn from( - ((left, right), (top, bottom)): ((usize, usize), (usize, usize)), + ((left, right), (top, bottom)): ((usize, usize), (usize, usize)) ) -> Vec4 { (left, right, top, bottom).into() } diff --git a/src/view/boxable.rs b/src/view/boxable.rs index 7565f54..b46d662 100644 --- a/src/view/boxable.rs +++ b/src/view/boxable.rs @@ -8,9 +8,7 @@ use views::BoxView; pub trait Boxable: View + Sized { /// Wraps `self` in a `BoxView` with the given size constraints. fn boxed( - self, - width: SizeConstraint, - height: SizeConstraint, + self, width: SizeConstraint, height: SizeConstraint ) -> BoxView { BoxView::new(width, height, self) } diff --git a/src/view/mod.rs b/src/view/mod.rs index 6ee0450..9856590 100644 --- a/src/view/mod.rs +++ b/src/view/mod.rs @@ -94,7 +94,6 @@ pub trait View: Any { EventResult::Ignored } - /// Returns the minimum size the view requires with the given restrictions. /// /// If the view is flexible (it has multiple size options), it can try diff --git a/src/view/position.rs b/src/view/position.rs index 8a6d089..d6e116e 100644 --- a/src/view/position.rs +++ b/src/view/position.rs @@ -30,10 +30,7 @@ impl Position { /// child with its top-left corner at the returned coordinates will /// position him appropriately. pub fn compute_offset( - &self, - size: S, - available: A, - parent: P, + &self, size: S, available: A, parent: P ) -> Vec2 where S: Into, @@ -68,10 +65,7 @@ pub enum Offset { impl Offset { /// Computes a single-dimension offset requred to draw a view. pub fn compute_offset( - &self, - size: usize, - available: usize, - parent: usize, + &self, size: usize, available: usize, parent: usize ) -> usize { if size > available { 0 diff --git a/src/view/view_wrapper.rs b/src/view/view_wrapper.rs index d0552b2..dd220f9 100644 --- a/src/view/view_wrapper.rs +++ b/src/view/view_wrapper.rs @@ -78,9 +78,7 @@ pub trait ViewWrapper: 'static { /// Wraps the `find` method. fn wrap_call_on_any<'a>( - &mut self, - selector: &Selector, - callback: Box, + &mut self, selector: &Selector, callback: Box ) { self.with_view_mut(|v| v.call_on_any(selector, callback)); } @@ -146,9 +144,7 @@ impl View for T { } fn call_on_any<'a>( - &mut self, - selector: &Selector, - callback: Box, + &mut self, selector: &Selector, callback: Box ) { self.wrap_call_on_any(selector, callback) } diff --git a/src/views/box_view.rs b/src/views/box_view.rs index 1200179..5391256 100644 --- a/src/views/box_view.rs +++ b/src/views/box_view.rs @@ -39,9 +39,7 @@ impl BoxView { /// /// `None` values will use the wrapped view's preferences. pub fn new( - width: SizeConstraint, - height: SizeConstraint, - view: T, + width: SizeConstraint, height: SizeConstraint, view: T ) -> Self { BoxView { size: (width, height).into(), diff --git a/src/views/checkbox.rs b/src/views/checkbox.rs index 7328328..6f8aef4 100644 --- a/src/views/checkbox.rs +++ b/src/views/checkbox.rs @@ -32,8 +32,7 @@ impl Checkbox { /// Sets a callback to be used when the state changes. pub fn set_on_change( - &mut self, - on_change: F, + &mut self, on_change: F ) { self.on_change = Some(Rc::new(on_change)); } @@ -42,8 +41,7 @@ impl Checkbox { /// /// Chainable variant. pub fn on_change( - self, - on_change: F, + self, on_change: F ) -> Self { self.with(|s| s.set_on_change(on_change)) } diff --git a/src/views/dialog.rs b/src/views/dialog.rs index 0bd368a..afa1930 100644 --- a/src/views/dialog.rs +++ b/src/views/dialog.rs @@ -108,7 +108,11 @@ impl Dialog { /// ``` /// use cursive::views::{Dialog, TextView}; /// let dialog = Dialog::around(TextView::new("Hello!")); - /// let text_view: &TextView = dialog.get_content().as_any().downcast_ref::().unwrap(); + /// let text_view: &TextView = dialog + /// .get_content() + /// .as_any() + /// .downcast_ref::() + /// .unwrap(); /// assert_eq!(text_view.get_content().source(), "Hello!"); /// ``` pub fn get_content(&self) -> &AnyView { @@ -235,7 +239,7 @@ impl Dialog { /// Returns an iterator on this buttons for this dialog. pub fn buttons_mut<'a>( - &'a mut self, + &'a mut self ) -> Box<'a + Iterator> { Box::new(self.buttons.iter_mut().map(|b| &mut b.button.view)) } @@ -265,9 +269,7 @@ impl Dialog { // An event is received while a button is in focus fn on_event_button( - &mut self, - event: Event, - button_id: usize, + &mut self, event: Event, button_id: usize ) -> EventResult { let result = { let button = &mut self.buttons[button_id]; @@ -550,9 +552,7 @@ impl View for Dialog { } fn call_on_any<'a>( - &mut self, - selector: &Selector, - callback: Box, + &mut self, selector: &Selector, callback: Box ) { self.content.call_on_any(selector, callback); } diff --git a/src/views/edit_view.rs b/src/views/edit_view.rs index 593000e..8a0783e 100644 --- a/src/views/edit_view.rs +++ b/src/views/edit_view.rs @@ -436,11 +436,9 @@ fn make_small_stars(length: usize) -> &'static str { impl View for EditView { fn draw(&self, printer: &Printer) { assert_eq!( - printer.size.x, - self.last_length, + printer.size.x, self.last_length, "Was promised {}, received {}", - self.last_length, - printer.size.x + self.last_length, printer.size.x ); let width = self.content.width(); @@ -513,8 +511,7 @@ impl View for EditView { .next() .expect(&format!( "Found no char at cursor {} in {}", - self.cursor, - &self.content + self.cursor, &self.content )); if self.secret { make_small_stars(selected.width()) diff --git a/src/views/id_view.rs b/src/views/id_view.rs index 166b2b8..5b957da 100644 --- a/src/views/id_view.rs +++ b/src/views/id_view.rs @@ -77,9 +77,7 @@ impl ViewWrapper for IdView { // Some for<'b> weirdness here to please the borrow checker gods... fn wrap_call_on_any<'a>( - &mut self, - selector: &Selector, - mut callback: BoxedCallback<'a>, + &mut self, selector: &Selector, mut callback: BoxedCallback<'a> ) { match selector { &Selector::Id(id) if id == self.id => callback(self), diff --git a/src/views/linear_layout.rs b/src/views/linear_layout.rs index a819a0f..9788c92 100644 --- a/src/views/linear_layout.rs +++ b/src/views/linear_layout.rs @@ -57,9 +57,7 @@ struct ChildItem { impl ChildIterator { fn new( - inner: T, - orientation: direction::Orientation, - available: usize, + inner: T, orientation: direction::Orientation, available: usize ) -> Self { ChildIterator { inner, @@ -71,7 +69,8 @@ impl ChildIterator { } impl<'a, T: Deref, I: Iterator> Iterator - for ChildIterator { + for ChildIterator +{ type Item = ChildItem; fn next(&mut self) -> Option { @@ -199,9 +198,7 @@ impl LinearLayout { /// Returns a cyclic mutable iterator starting with the child in focus fn iter_mut<'a>( - &'a mut self, - from_focus: bool, - source: direction::Relative, + &'a mut self, from_focus: bool, source: direction::Relative ) -> Box + 'a> { match source { direction::Relative::Front => { @@ -290,8 +287,7 @@ impl LinearLayout { } fn try_focus( - (i, child): (usize, &mut Child), - source: direction::Direction, + (i, child): (usize, &mut Child), source: direction::Direction ) -> Option { if child.view.take_focus(source) { Some(i) @@ -553,8 +549,7 @@ impl View for LinearLayout { } fn call_on_any<'a>( - &mut self, - selector: &Selector, + &mut self, selector: &Selector, mut callback: Box, ) { for child in &mut self.children { diff --git a/src/views/list_view.rs b/src/views/list_view.rs index 4925d99..5032d7d 100644 --- a/src/views/list_view.rs +++ b/src/views/list_view.rs @@ -148,9 +148,7 @@ impl ListView { } fn iter_mut<'a>( - &'a mut self, - from_focus: bool, - source: direction::Relative, + &'a mut self, from_focus: bool, source: direction::Relative ) -> Box + 'a> { match source { direction::Relative::Front => { @@ -174,9 +172,7 @@ impl ListView { } fn move_focus( - &mut self, - n: usize, - source: direction::Direction, + &mut self, n: usize, source: direction::Direction ) -> EventResult { let i = if let Some(i) = source .relative(direction::Orientation::Vertical) @@ -250,8 +246,7 @@ impl ListView { } fn try_focus( - (i, child): (usize, &mut ListChild), - source: direction::Direction, + (i, child): (usize, &mut ListChild), source: direction::Direction ) -> Option { match *child { ListChild::Delimiter => None, @@ -454,8 +449,7 @@ impl View for ListView { } fn call_on_any<'a>( - &mut self, - selector: &Selector, + &mut self, selector: &Selector, mut callback: Box, ) { for view in self.children.iter_mut().filter_map(ListChild::view) { diff --git a/src/views/menubar.rs b/src/views/menubar.rs index 26436d8..abb83fc 100644 --- a/src/views/menubar.rs +++ b/src/views/menubar.rs @@ -106,10 +106,7 @@ impl Menubar { /// Insert a new item at the given position. pub fn insert_subtree( - &mut self, - i: usize, - title: S, - menu: MenuTree, + &mut self, i: usize, title: S, menu: MenuTree ) -> &mut Self where S: Into, diff --git a/src/views/progress_bar.rs b/src/views/progress_bar.rs index ce8344d..44538e4 100644 --- a/src/views/progress_bar.rs +++ b/src/views/progress_bar.rs @@ -123,8 +123,7 @@ impl ProgressBar { /// /// Chainable variant. pub fn with_task( - mut self, - task: F, + mut self, task: F ) -> Self { self.start(task); self @@ -144,8 +143,7 @@ impl ProgressBar { /// } /// ``` pub fn with_label String + 'static>( - mut self, - label_maker: F, + mut self, label_maker: F ) -> Self { self.label_maker = Box::new(label_maker); self diff --git a/src/views/radio.rs b/src/views/radio.rs index f6b8c80..15cd4e3 100644 --- a/src/views/radio.rs +++ b/src/views/radio.rs @@ -52,9 +52,7 @@ impl RadioGroup { /// /// The button will display `label` next to it, and will embed `value`. pub fn button>( - &mut self, - value: T, - label: S, + &mut self, value: T, label: S ) -> RadioButton { let count = self.state.borrow().values.len(); self.state.borrow_mut().values.push(Rc::new(value)); @@ -77,8 +75,7 @@ impl RadioGroup { impl RadioGroup { /// Adds a button, using the label itself as value. pub fn button_str>( - &mut self, - text: S, + &mut self, text: S ) -> RadioButton { let text = text.into(); self.button(text.clone(), text) @@ -107,9 +104,7 @@ impl RadioButton { impl_enabled!(self.enabled); fn new( - state: Rc>>, - id: usize, - label: String, + state: Rc>>, id: usize, label: String ) -> Self { RadioButton { state: state, diff --git a/src/views/stack_view.rs b/src/views/stack_view.rs index cb6e29b..3fc3e1c 100644 --- a/src/views/stack_view.rs +++ b/src/views/stack_view.rs @@ -33,10 +33,7 @@ pub enum LayerPosition { impl Placement { pub fn compute_offset( - &self, - size: S, - available: A, - parent: P, + &self, size: S, available: A, parent: P ) -> Vec2 where S: Into, @@ -110,9 +107,7 @@ impl View for ChildWrapper { } fn call_on_any<'a>( - &mut self, - selector: &Selector, - callback: Box, + &mut self, selector: &Selector, callback: Box ) { match *self { ChildWrapper::Shadow(ref mut v) => { @@ -294,7 +289,8 @@ struct StackPositionIterator, I: Iterator> { } impl, I: Iterator> - StackPositionIterator { + StackPositionIterator +{ /// Returns a new StackPositionIterator pub fn new(inner: I, total_size: Vec2) -> Self { let previous = Vec2::zero(); @@ -307,7 +303,8 @@ impl, I: Iterator> } impl, I: Iterator> Iterator - for StackPositionIterator { + for StackPositionIterator +{ type Item = (R, Vec2); fn next(&mut self) -> Option<(R, Vec2)> { @@ -396,8 +393,7 @@ impl View for StackView { } fn call_on_any<'a>( - &mut self, - selector: &Selector, + &mut self, selector: &Selector, mut callback: Box, ) { for layer in &mut self.layers {