Run cargo fix --edition-idioms

This commit is contained in:
Alexandre Bury 2019-02-28 15:55:02 -08:00
parent e51be07e5d
commit e096dc9740
49 changed files with 186 additions and 190 deletions

View File

@ -3,7 +3,7 @@
//! Requires the `blt-backend` feature. //! Requires the `blt-backend` feature.
#![cfg(feature = "bear-lib-terminal")] #![cfg(feature = "bear-lib-terminal")]
extern crate bear_lib_terminal; use bear_lib_terminal;
use std::collections::HashSet; use std::collections::HashSet;
@ -31,7 +31,7 @@ pub struct Backend {
impl Backend { impl Backend {
/// Creates a new BearLibTerminal-based backend. /// Creates a new BearLibTerminal-based backend.
pub fn init() -> Box<backend::Backend> { pub fn init() -> Box<dyn backend::Backend> {
terminal::open("Cursive", 80, 24); terminal::open("Cursive", 80, 24);
terminal::set(terminal::config::Window::empty().resizeable(true)); terminal::set(terminal::config::Window::empty().resizeable(true));
terminal::set(vec![ terminal::set(vec![

View File

@ -1,5 +1,5 @@
//! Ncurses-specific backend. //! Ncurses-specific backend.
extern crate ncurses; use ncurses;
use std::cell::{Cell, RefCell}; use std::cell::{Cell, RefCell};
use std::collections::HashMap; use std::collections::HashMap;
@ -56,7 +56,7 @@ fn write_to_tty(bytes: &[u8]) -> io::Result<()> {
impl Backend { impl Backend {
/// Creates a new ncurses-based backend. /// Creates a new ncurses-based backend.
pub fn init() -> Box<backend::Backend> { pub fn init() -> Box<dyn backend::Backend> {
// Change the locale. // Change the locale.
// For some reasons it's mandatory to get some UTF-8 support. // For some reasons it's mandatory to get some UTF-8 support.
ncurses::setlocale(ncurses::LcCategory::all, ""); ncurses::setlocale(ncurses::LcCategory::all, "");

View File

@ -1,5 +1,5 @@
//! Pancuses-specific backend. //! Pancuses-specific backend.
extern crate pancurses; use pancurses;
use std::cell::{Cell, RefCell}; use std::cell::{Cell, RefCell};
use std::collections::HashMap; use std::collections::HashMap;
@ -33,7 +33,7 @@ fn find_closest_pair(pair: ColorPair) -> (i16, i16) {
impl Backend { impl Backend {
/// Creates a new pancurses-based backend. /// Creates a new pancurses-based backend.
pub fn init() -> Box<backend::Backend> { pub fn init() -> Box<dyn backend::Backend> {
::std::env::set_var("ESCDELAY", "25"); ::std::env::set_var("ESCDELAY", "25");
let window = pancurses::initscr(); let window = pancurses::initscr();

View File

@ -12,7 +12,7 @@ pub struct Backend;
impl Backend { impl Backend {
/// Creates a new dummy backend. /// Creates a new dummy backend.
pub fn init() -> Box<backend::Backend> pub fn init() -> Box<dyn backend::Backend>
where where
Self: Sized, Self: Sized,
{ {

View File

@ -3,7 +3,7 @@
//! Requires the `termion-backend` feature. //! Requires the `termion-backend` feature.
#![cfg(feature = "termion")] #![cfg(feature = "termion")]
extern crate termion; use termion;
use self::termion::color as tcolor; use self::termion::color as tcolor;
use self::termion::event::Event as TEvent; use self::termion::event::Event as TEvent;
@ -43,7 +43,7 @@ pub struct Backend {
impl Backend { impl Backend {
/// Creates a new termion-based backend. /// Creates a new termion-based backend.
pub fn init() -> Box<backend::Backend> { pub fn init() -> Box<dyn backend::Backend> {
// Use a ~8MB buffer // Use a ~8MB buffer
// Should be enough for a single screen most of the time. // Should be enough for a single screen most of the time.
let terminal = let terminal =
@ -284,7 +284,7 @@ impl backend::Backend for Backend {
fn with_color<F, R>(clr: &theme::Color, f: F) -> R fn with_color<F, R>(clr: &theme::Color, f: F) -> R
where where
F: FnOnce(&tcolor::Color) -> R, F: FnOnce(&dyn tcolor::Color) -> R,
{ {
match *clr { match *clr {
theme::Color::TerminalDefault => f(&tcolor::Reset), theme::Color::TerminalDefault => f(&tcolor::Reset),

View File

@ -39,17 +39,17 @@ pub struct Cursive {
running: bool, running: bool,
backend: Box<backend::Backend>, backend: Box<dyn backend::Backend>,
cb_source: Receiver<Box<CbFunc>>, cb_source: Receiver<Box<dyn CbFunc>>,
cb_sink: Sender<Box<CbFunc>>, cb_sink: Sender<Box<dyn CbFunc>>,
} }
/// Identifies a screen in the cursive root. /// Identifies a screen in the cursive root.
pub type ScreenId = usize; pub type ScreenId = usize;
/// Convenient alias to the result of `Cursive::cb_sink`. /// Convenient alias to the result of `Cursive::cb_sink`.
pub type CbSink = Sender<Box<CbFunc>>; pub type CbSink = Sender<Box<dyn CbFunc>>;
/// Asynchronous callback function trait. /// Asynchronous callback function trait.
/// ///
@ -127,7 +127,7 @@ impl Cursive {
/// ``` /// ```
pub fn new<F>(backend_init: F) -> Self pub fn new<F>(backend_init: F) -> Self
where where
F: FnOnce() -> Box<backend::Backend>, F: FnOnce() -> Box<dyn backend::Backend>,
{ {
let theme = theme::load_default(); let theme = theme::load_default();
@ -422,7 +422,7 @@ impl Cursive {
/// # } /// # }
/// ``` /// ```
pub fn call_on<V, F, R>( pub fn call_on<V, F, R>(
&mut self, sel: &view::Selector, callback: F, &mut self, sel: &view::Selector<'_>, callback: F,
) -> Option<R> ) -> Option<R>
where where
V: View + Any, V: View + Any,
@ -522,7 +522,7 @@ impl Cursive {
} }
/// Moves the focus to the view identified by `sel`. /// Moves the focus to the view identified by `sel`.
pub fn focus(&mut self, sel: &view::Selector) -> Result<(), ()> { pub fn focus(&mut self, sel: &view::Selector<'_>) -> Result<(), ()> {
self.screen_mut().focus_view(sel) self.screen_mut().focus_view(sel)
} }
@ -604,7 +604,7 @@ impl Cursive {
} }
/// Convenient method to remove a layer from the current screen. /// Convenient method to remove a layer from the current screen.
pub fn pop_layer(&mut self) -> Option<Box<View>> { pub fn pop_layer(&mut self) -> Option<Box<dyn View>> {
self.screen_mut().pop_layer() self.screen_mut().pop_layer()
} }

View File

@ -23,14 +23,14 @@ use crate::Cursive;
/// Callback is a function that can be triggered by an event. /// Callback is a function that can be triggered by an event.
/// It has a mutable access to the cursive root. /// It has a mutable access to the cursive root.
#[derive(Clone)] #[derive(Clone)]
pub struct Callback(Rc<Box<Fn(&mut Cursive)>>); pub struct Callback(Rc<Box<dyn Fn(&mut Cursive)>>);
// TODO: remove the Box when Box<T: Sized> -> Rc<T> is possible // TODO: remove the Box when Box<T: Sized> -> Rc<T> is possible
/// A boxed callback that can be run on `&mut Any`. /// A boxed callback that can be run on `&mut Any`.
pub type AnyCb<'a> = Box<FnMut(&mut Any) + 'a>; pub type AnyCb<'a> = Box<FnMut(&mut dyn Any) + 'a>;
/// A trigger that only selects some types of events. /// A trigger that only selects some types of events.
pub struct EventTrigger(Box<Fn(&Event) -> bool>); pub struct EventTrigger(Box<dyn Fn(&Event) -> bool>);
impl EventTrigger { impl EventTrigger {
/// Create a new `EventTrigger` using the given function as filter. /// Create a new `EventTrigger` using the given function as filter.
@ -148,26 +148,26 @@ impl Callback {
} }
impl Deref for Callback { impl Deref for Callback {
type Target = Box<Fn(&mut Cursive)>; type Target = Box<dyn Fn(&mut Cursive)>;
fn deref<'a>(&'a self) -> &'a Box<Fn(&mut Cursive)> { fn deref<'a>(&'a self) -> &'a Box<dyn Fn(&mut Cursive)> {
&self.0 &self.0
} }
} }
impl From<Rc<Box<Fn(&mut Cursive)>>> for Callback { impl From<Rc<Box<dyn Fn(&mut Cursive)>>> for Callback {
fn from(f: Rc<Box<Fn(&mut Cursive)>>) -> Self { fn from(f: Rc<Box<dyn Fn(&mut Cursive)>>) -> Self {
Callback(f) Callback(f)
} }
} }
impl From<Box<Fn(&mut Cursive) + Send>> for Callback { impl From<Box<dyn Fn(&mut Cursive) + Send>> for Callback {
fn from(f: Box<Fn(&mut Cursive) + Send>) -> Self { fn from(f: Box<dyn Fn(&mut Cursive) + Send>) -> Self {
Callback(Rc::new(f)) Callback(Rc::new(f))
} }
} }
impl From<Box<Fn(&mut Cursive)>> for Callback { impl From<Box<dyn Fn(&mut Cursive)>> for Callback {
fn from(f: Box<Fn(&mut Cursive)>) -> Self { fn from(f: Box<dyn Fn(&mut Cursive)>) -> Self {
Callback(Rc::new(f)) Callback(Rc::new(f))
} }
} }

View File

@ -78,17 +78,16 @@ extern crate maplit;
// We use chan_signal to detect SIGWINCH. // We use chan_signal to detect SIGWINCH.
// It's not how windows work, so no need to use that. // It's not how windows work, so no need to use that.
#[cfg(unix)]
extern crate signal_hook;
extern crate chrono;
extern crate libc;
extern crate num;
extern crate owning_ref;
extern crate toml;
extern crate unicode_segmentation;
extern crate unicode_width;
extern crate xi_unicode;
macro_rules! new_default( macro_rules! new_default(
($c:ty) => { ($c:ty) => {

View File

@ -27,11 +27,11 @@ lazy_static! {
} }
impl log::Log for CursiveLogger { impl log::Log for CursiveLogger {
fn enabled(&self, _metadata: &log::Metadata) -> bool { fn enabled(&self, _metadata: &log::Metadata<'_>) -> bool {
true true
} }
fn log(&self, record: &log::Record) { fn log(&self, record: &log::Record<'_>) {
let mut logs = LOGS.lock().unwrap(); let mut logs = LOGS.lock().unwrap();
// TODO: customize the format? Use colors? Save more info? // TODO: customize the format? Use colors? Save more info?
if logs.len() == logs.capacity() { if logs.len() == logs.capacity() {

View File

@ -50,7 +50,7 @@ pub struct Printer<'a, 'b> {
pub theme: &'a Theme, pub theme: &'a Theme,
/// Backend used to actually draw things /// Backend used to actually draw things
backend: &'b Backend, backend: &'b dyn Backend,
} }
impl<'a, 'b> Printer<'a, 'b> { impl<'a, 'b> Printer<'a, 'b> {
@ -59,7 +59,7 @@ impl<'a, 'b> Printer<'a, 'b> {
/// But nobody needs to know that. /// But nobody needs to know that.
#[doc(hidden)] #[doc(hidden)]
pub fn new<T: Into<Vec2>>( pub fn new<T: Into<Vec2>>(
size: T, theme: &'a Theme, backend: &'b Backend, size: T, theme: &'a Theme, backend: &'b dyn Backend,
) -> Self { ) -> Self {
let size = size.into(); let size = size.into();
Printer { Printer {
@ -265,7 +265,7 @@ impl<'a, 'b> Printer<'a, 'b> {
/// ``` /// ```
pub fn with_color<F>(&self, c: ColorStyle, f: F) pub fn with_color<F>(&self, c: ColorStyle, f: F)
where where
F: FnOnce(&Printer), F: FnOnce(&Printer<'_, '_>),
{ {
let old = self.backend.set_color(c.resolve(&self.theme.palette)); let old = self.backend.set_color(c.resolve(&self.theme.palette));
f(self); f(self);
@ -276,7 +276,7 @@ impl<'a, 'b> Printer<'a, 'b> {
/// that will apply the given style on prints. /// that will apply the given style on prints.
pub fn with_style<F, T>(&self, style: T, f: F) pub fn with_style<F, T>(&self, style: T, f: F)
where where
F: FnOnce(&Printer), F: FnOnce(&Printer<'_, '_>),
T: Into<Style>, T: Into<Style>,
{ {
let style = style.into(); let style = style.into();
@ -297,7 +297,7 @@ impl<'a, 'b> Printer<'a, 'b> {
/// that will apply the given effect on prints. /// that will apply the given effect on prints.
pub fn with_effect<F>(&self, effect: Effect, f: F) pub fn with_effect<F>(&self, effect: Effect, f: F)
where where
F: FnOnce(&Printer), F: FnOnce(&Printer<'_, '_>),
{ {
self.backend.set_effect(effect); self.backend.set_effect(effect);
f(self); f(self);
@ -308,7 +308,7 @@ impl<'a, 'b> Printer<'a, 'b> {
/// that will apply the given theme on prints. /// that will apply the given theme on prints.
pub fn with_theme<F>(&self, theme: &Theme, f: F) pub fn with_theme<F>(&self, theme: &Theme, f: F)
where where
F: FnOnce(&Printer), F: FnOnce(&Printer<'_, '_>),
{ {
f(&self.theme(theme)); f(&self.theme(theme));
} }
@ -328,7 +328,7 @@ impl<'a, 'b> Printer<'a, 'b> {
/// that will apply each given effect on prints. /// that will apply each given effect on prints.
pub fn with_effects<F>(&self, effects: EnumSet<Effect>, f: F) pub fn with_effects<F>(&self, effects: EnumSet<Effect>, f: F)
where where
F: FnOnce(&Printer), F: FnOnce(&Printer<'_, '_>),
{ {
match effects.iter().next() { match effects.iter().next() {
None => f(self), None => f(self),
@ -391,7 +391,7 @@ impl<'a, 'b> Printer<'a, 'b> {
/// * Otherwise, use `ColorStyle::Primary`. /// * Otherwise, use `ColorStyle::Primary`.
pub fn with_high_border<F>(&self, invert: bool, f: F) pub fn with_high_border<F>(&self, invert: bool, f: F)
where where
F: FnOnce(&Printer), F: FnOnce(&Printer<'_, '_>),
{ {
let color = match self.theme.borders { let color = match self.theme.borders {
BorderStyle::None => return, BorderStyle::None => return,
@ -410,7 +410,7 @@ impl<'a, 'b> Printer<'a, 'b> {
/// * Otherwise, use `ColorStyle::primary()`. /// * Otherwise, use `ColorStyle::primary()`.
pub fn with_low_border<F>(&self, invert: bool, f: F) pub fn with_low_border<F>(&self, invert: bool, f: F)
where where
F: FnOnce(&Printer), F: FnOnce(&Printer<'_, '_>),
{ {
let color = match self.theme.borders { let color = match self.theme.borders {
BorderStyle::None => return, BorderStyle::None => return,
@ -428,7 +428,7 @@ impl<'a, 'b> Printer<'a, 'b> {
/// * If the printer currently has the focus, /// * If the printer currently has the focus,
/// uses `ColorStyle::highlight()`. /// uses `ColorStyle::highlight()`.
/// * Otherwise, uses `ColorStyle::highlight_inactive()`. /// * Otherwise, uses `ColorStyle::highlight_inactive()`.
pub fn with_selection<F: FnOnce(&Printer)>(&self, selection: bool, f: F) { pub fn with_selection<F: FnOnce(&Printer<'_, '_>)>(&self, selection: bool, f: F) {
self.with_color( self.with_color(
if selection { if selection {
if self.focused { if self.focused {
@ -457,7 +457,7 @@ impl<'a, 'b> Printer<'a, 'b> {
/// Returns a sub-printer with the given offset. /// Returns a sub-printer with the given offset.
/// ///
/// It will print in an area slightly to the bottom/right. /// It will print in an area slightly to the bottom/right.
pub fn offset<S>(&self, offset: S) -> Printer pub fn offset<S>(&self, offset: S) -> Printer<'_, '_>
where where
S: Into<Vec2>, S: Into<Vec2>,
{ {

View File

@ -198,9 +198,9 @@ fn load_hex(s: &str) -> u16 {
for c in s.chars() { for c in s.chars() {
sum *= 16; sum *= 16;
sum += match c { sum += match c {
n @ '0'...'9' => n as i16 - '0' as i16, n @ '0'..='9' => n as i16 - '0' as i16,
n @ 'a'...'f' => n as i16 - 'a' as i16 + 10, n @ 'a'..='f' => n as i16 - 'a' as i16 + 10,
n @ 'A'...'F' => n as i16 - 'A' as i16 + 10, n @ 'A'..='F' => n as i16 - 'A' as i16 + 10,
_ => 0, _ => 0,
}; };
} }

View File

@ -17,9 +17,9 @@ where
// Number of leading 1s determines the number of bytes we'll have to read // Number of leading 1s determines the number of bytes we'll have to read
let n_bytes = match (!first).leading_zeros() { let n_bytes = match (!first).leading_zeros() {
n @ 2...6 => n as usize, n @ 2..=6 => n as usize,
1 => return Err("First byte is continuation byte.".to_string()), 1 => return Err("First byte is continuation byte.".to_string()),
7...8 => return Err("WTF is this byte??".to_string()), 7..=8 => return Err("WTF is this byte??".to_string()),
_ => unreachable!(), _ => unreachable!(),
}; };

View File

@ -2,7 +2,7 @@
//! //!
//! Needs the `markdown` feature to be enabled. //! Needs the `markdown` feature to be enabled.
extern crate pulldown_cmark; use pulldown_cmark;
use self::pulldown_cmark::{Event, Tag}; use self::pulldown_cmark::{Event, Tag};
use crate::theme::{Effect, Style}; use crate::theme::{Effect, Style};

View File

@ -16,10 +16,7 @@ pub struct SpannedString<T> {
/// The immutable, borrowed equivalent of `SpannedString`. /// The immutable, borrowed equivalent of `SpannedString`.
#[derive(Debug, PartialEq, Eq)] #[derive(Debug, PartialEq, Eq)]
pub struct SpannedStr<'a, T> pub struct SpannedStr<'a, T> {
where
T: 'a,
{
source: &'a str, source: &'a str,
spans: &'a [IndexedSpan<T>], spans: &'a [IndexedSpan<T>],
} }
@ -45,7 +42,7 @@ pub trait SpannedText {
/// A reference to another `SpannedText`. /// A reference to another `SpannedText`.
pub struct SpannedTextRef<'a, C> pub struct SpannedTextRef<'a, C>
where where
C: 'a + SpannedText + ?Sized, C: SpannedText + ?Sized,
{ {
r: &'a C, r: &'a C,
} }
@ -288,7 +285,7 @@ impl<T> AsRef<IndexedCow> for IndexedSpan<T> {
/// A resolved span borrowing its source string. /// A resolved span borrowing its source string.
#[derive(Debug, Clone, PartialEq, Eq)] #[derive(Debug, Clone, PartialEq, Eq)]
pub struct Span<'a, T: 'a> { pub struct Span<'a, T> {
/// Content of this span. /// Content of this span.
pub content: &'a str, pub content: &'a str,
@ -353,7 +350,7 @@ impl IndexedCow {
/// Returns an indexed view of the given item. /// Returns an indexed view of the given item.
/// ///
/// **Note**: it is assumed `cow`, if borrowed, is a substring of `source`. /// **Note**: it is assumed `cow`, if borrowed, is a substring of `source`.
pub fn from_cow(cow: Cow<str>, source: &str) -> Self { pub fn from_cow(cow: Cow<'_, str>, source: &str) -> Self {
match cow { match cow {
Cow::Owned(value) => IndexedCow::Owned(value), Cow::Owned(value) => IndexedCow::Owned(value),
Cow::Borrowed(value) => { Cow::Borrowed(value) => {

View File

@ -6,10 +6,10 @@ use crate::view::View;
/// This trait is automatically implemented for any `T: View`. /// This trait is automatically implemented for any `T: View`.
pub trait AnyView { pub trait AnyView {
/// Downcast self to a `Any`. /// Downcast self to a `Any`.
fn as_any(&self) -> &Any; fn as_any(&self) -> &dyn Any;
/// Downcast self to a mutable `Any`. /// Downcast self to a mutable `Any`.
fn as_any_mut(&mut self) -> &mut Any; fn as_any_mut(&mut self) -> &mut dyn Any;
/// Returns a boxed any from a boxed self. /// Returns a boxed any from a boxed self.
/// ///
@ -25,21 +25,21 @@ pub trait AnyView {
/// let text: Box<TextView> = boxed.as_boxed_any().downcast().unwrap(); /// let text: Box<TextView> = boxed.as_boxed_any().downcast().unwrap();
/// # } /// # }
/// ``` /// ```
fn as_boxed_any(self: Box<Self>) -> Box<Any>; fn as_boxed_any(self: Box<Self>) -> Box<dyn Any>;
} }
impl<T: View> AnyView for T { impl<T: View> AnyView for T {
/// Downcast self to a `Any`. /// Downcast self to a `Any`.
fn as_any(&self) -> &Any { fn as_any(&self) -> &dyn Any {
self self
} }
/// Downcast self to a mutable `Any`. /// Downcast self to a mutable `Any`.
fn as_any_mut(&mut self) -> &mut Any { fn as_any_mut(&mut self) -> &mut dyn Any {
self self
} }
fn as_boxed_any(self: Box<Self>) -> Box<Any> { fn as_boxed_any(self: Box<Self>) -> Box<dyn Any> {
self self
} }
} }

View File

@ -16,7 +16,7 @@ pub trait Finder {
/// ///
/// If the view is not found, or if it is not of the asked type, /// If the view is not found, or if it is not of the asked type,
/// it returns `None`. /// it returns `None`.
fn call_on<V, F, R>(&mut self, sel: &Selector, callback: F) -> Option<R> fn call_on<V, F, R>(&mut self, sel: &Selector<'_>, callback: F) -> Option<R>
where where
V: View + Any, V: View + Any,
F: FnOnce(&mut V) -> R; F: FnOnce(&mut V) -> R;
@ -42,7 +42,7 @@ pub trait Finder {
} }
impl<T: View> Finder for T { impl<T: View> Finder for T {
fn call_on<V, F, R>(&mut self, sel: &Selector, callback: F) -> Option<R> fn call_on<V, F, R>(&mut self, sel: &Selector<'_>, callback: F) -> Option<R>
where where
V: View + Any, V: View + Any,
F: FnOnce(&mut V) -> R, F: FnOnce(&mut V) -> R,
@ -52,7 +52,7 @@ impl<T: View> Finder for T {
let result_ref = &mut result; let result_ref = &mut result;
let mut callback = Some(callback); let mut callback = Some(callback);
let callback = |v: &mut Any| { let callback = |v: &mut dyn Any| {
if let Some(callback) = callback.take() { if let Some(callback) = callback.take() {
if v.is::<V>() { if v.is::<V>() {
*result_ref = *result_ref =

View File

@ -3,20 +3,20 @@ use crate::view::View;
/// Represents a type that can be made into a `Box<View>`. /// Represents a type that can be made into a `Box<View>`.
pub trait IntoBoxedView { pub trait IntoBoxedView {
/// Returns a `Box<View>`. /// Returns a `Box<View>`.
fn as_boxed_view(self) -> Box<View>; fn as_boxed_view(self) -> Box<dyn View>;
} }
impl<T> IntoBoxedView for T impl<T> IntoBoxedView for T
where where
T: View, T: View,
{ {
fn as_boxed_view(self) -> Box<View> { fn as_boxed_view(self) -> Box<dyn View> {
Box::new(self) Box::new(self)
} }
} }
impl IntoBoxedView for Box<View> { impl IntoBoxedView for Box<dyn View> {
fn as_boxed_view(self) -> Box<View> { fn as_boxed_view(self) -> Box<dyn View> {
self self
} }
} }

View File

@ -241,9 +241,9 @@ impl ScrollBase {
/// printer.print((0,0), lines[i]); /// printer.print((0,0), lines[i]);
/// }); /// });
/// ``` /// ```
pub fn draw<F>(&self, printer: &Printer, line_drawer: F) pub fn draw<F>(&self, printer: &Printer<'_, '_>, line_drawer: F)
where where
F: Fn(&Printer, usize), F: Fn(&Printer<'_, '_>, usize),
{ {
if self.view_height == 0 { if self.view_height == 0 {
return; return;

View File

@ -13,7 +13,7 @@ pub trait View: Any + AnyView {
/// Draws the view with the given printer (includes bounds) and focus. /// Draws the view with the given printer (includes bounds) and focus.
/// ///
/// This is the only *required* method to implement. /// This is the only *required* method to implement.
fn draw(&self, printer: &Printer); fn draw(&self, printer: &Printer<'_, '_>);
/// Called once the size for this view has been decided. /// Called once the size for this view has been decided.
/// ///
@ -83,7 +83,7 @@ pub trait View: Any + AnyView {
/// View groups should implement this to forward the call to each children. /// View groups should implement this to forward the call to each children.
/// ///
/// Default implementation is a no-op. /// Default implementation is a no-op.
fn call_on_any<'a>(&mut self, _: &Selector, _: AnyCb<'a>) { fn call_on_any<'a>(&mut self, _: &Selector<'_>, _: AnyCb<'a>) {
// TODO: FnMut -> FnOnce once it works // TODO: FnMut -> FnOnce once it works
} }
@ -92,7 +92,7 @@ pub trait View: Any + AnyView {
/// Returns `Ok(())` if the view was found and selected. /// Returns `Ok(())` if the view was found and selected.
/// ///
/// Default implementation simply returns `Err(())`. /// Default implementation simply returns `Err(())`.
fn focus_view(&mut self, _: &Selector) -> Result<(), ()> { fn focus_view(&mut self, _: &Selector<'_>) -> Result<(), ()> {
Err(()) Err(())
} }

View File

@ -50,7 +50,7 @@ pub trait ViewWrapper: 'static {
} }
/// Wraps the `draw` method. /// Wraps the `draw` method.
fn wrap_draw(&self, printer: &Printer) { fn wrap_draw(&self, printer: &Printer<'_, '_>) {
self.with_view(|v| v.draw(printer)); self.with_view(|v| v.draw(printer));
} }
@ -79,13 +79,13 @@ pub trait ViewWrapper: 'static {
/// Wraps the `find` method. /// Wraps the `find` method.
fn wrap_call_on_any<'a>( fn wrap_call_on_any<'a>(
&mut self, selector: &Selector, callback: AnyCb<'a>, &mut self, selector: &Selector<'_>, callback: AnyCb<'a>,
) { ) {
self.with_view_mut(|v| v.call_on_any(selector, callback)); self.with_view_mut(|v| v.call_on_any(selector, callback));
} }
/// Wraps the `focus_view` method. /// Wraps the `focus_view` method.
fn wrap_focus_view(&mut self, selector: &Selector) -> Result<(), ()> { fn wrap_focus_view(&mut self, selector: &Selector<'_>) -> Result<(), ()> {
self.with_view_mut(|v| v.focus_view(selector)) self.with_view_mut(|v| v.focus_view(selector))
.unwrap_or(Err(())) .unwrap_or(Err(()))
} }
@ -104,7 +104,7 @@ pub trait ViewWrapper: 'static {
// The main point of implementing ViewWrapper is to have View for free. // The main point of implementing ViewWrapper is to have View for free.
impl<T: ViewWrapper> View for T { impl<T: ViewWrapper> View for T {
fn draw(&self, printer: &Printer) { fn draw(&self, printer: &Printer<'_, '_>) {
self.wrap_draw(printer); self.wrap_draw(printer);
} }
@ -125,7 +125,7 @@ impl<T: ViewWrapper> View for T {
} }
fn call_on_any<'a>( fn call_on_any<'a>(
&mut self, selector: &Selector, callback: Box<FnMut(&mut Any) + 'a>, &mut self, selector: &Selector<'_>, callback: Box<FnMut(&mut dyn Any) + 'a>,
) { ) {
self.wrap_call_on_any(selector, callback) self.wrap_call_on_any(selector, callback)
} }
@ -134,7 +134,7 @@ impl<T: ViewWrapper> View for T {
self.wrap_needs_relayout() self.wrap_needs_relayout()
} }
fn focus_view(&mut self, selector: &Selector) -> Result<(), ()> { fn focus_view(&mut self, selector: &Selector<'_>) -> Result<(), ()> {
self.wrap_focus_view(selector) self.wrap_focus_view(selector)
} }

View File

@ -137,7 +137,7 @@ impl Button {
} }
impl View for Button { impl View for Button {
fn draw(&self, printer: &Printer) { fn draw(&self, printer: &Printer<'_, '_>) {
if printer.size.x == 0 { if printer.size.x == 0 {
return; return;
} }

View File

@ -12,15 +12,15 @@ use crate::With;
pub struct Canvas<T> { pub struct Canvas<T> {
state: T, state: T,
draw: Box<Fn(&T, &Printer)>, draw: Box<dyn Fn(&T, &Printer)>,
on_event: Box<FnMut(&mut T, Event) -> EventResult>, on_event: Box<dyn FnMut(&mut T, Event) -> EventResult>,
required_size: Box<FnMut(&mut T, Vec2) -> Vec2>, required_size: Box<dyn FnMut(&mut T, Vec2) -> Vec2>,
layout: Box<FnMut(&mut T, Vec2)>, layout: Box<dyn FnMut(&mut T, Vec2)>,
take_focus: Box<FnMut(&mut T, Direction) -> bool>, take_focus: Box<dyn FnMut(&mut T, Direction) -> bool>,
needs_relayout: Box<Fn(&T) -> bool>, needs_relayout: Box<dyn Fn(&T) -> bool>,
focus_view: Box<FnMut(&mut T, &Selector) -> Result<(), ()>>, focus_view: Box<dyn FnMut(&mut T, &Selector) -> Result<(), ()>>,
call_on_any: Box<for<'a> FnMut(&mut T, &Selector, AnyCb<'a>)>, call_on_any: Box<dyn for<'a> FnMut(&mut T, &Selector, AnyCb<'a>)>,
important_area: Box<Fn(&T, Vec2) -> Rect>, important_area: Box<dyn Fn(&T, Vec2) -> Rect>,
} }
impl<T: 'static + View> Canvas<T> { impl<T: 'static + View> Canvas<T> {
@ -78,7 +78,7 @@ impl<T> Canvas<T> {
/// Sets the closure for `draw(&Printer)`. /// Sets the closure for `draw(&Printer)`.
pub fn set_draw<F>(&mut self, f: F) pub fn set_draw<F>(&mut self, f: F)
where where
F: 'static + Fn(&T, &Printer), F: 'static + Fn(&T, &Printer<'_, '_>),
{ {
self.draw = Box::new(f); self.draw = Box::new(f);
} }
@ -88,7 +88,7 @@ impl<T> Canvas<T> {
/// Chainable variant. /// Chainable variant.
pub fn with_draw<F>(self, f: F) -> Self pub fn with_draw<F>(self, f: F) -> Self
where where
F: 'static + Fn(&T, &Printer), F: 'static + Fn(&T, &Printer<'_, '_>),
{ {
self.with(|s| s.set_draw(f)) self.with(|s| s.set_draw(f))
} }
@ -186,7 +186,7 @@ impl<T> Canvas<T> {
/// Sets the closure for `call_on_any()`. /// Sets the closure for `call_on_any()`.
pub fn set_call_on_any<F>(&mut self, f: F) pub fn set_call_on_any<F>(&mut self, f: F)
where where
F: 'static + for<'a> FnMut(&mut T, &Selector, AnyCb<'a>), F: 'static + for<'a> FnMut(&mut T, &Selector<'_>, AnyCb<'a>),
{ {
self.call_on_any = Box::new(f); self.call_on_any = Box::new(f);
} }
@ -196,7 +196,7 @@ impl<T> Canvas<T> {
/// Chainable variant. /// Chainable variant.
pub fn with_call_on_any<F>(self, f: F) -> Self pub fn with_call_on_any<F>(self, f: F) -> Self
where where
F: 'static + for<'a> FnMut(&mut T, &Selector, AnyCb<'a>), F: 'static + for<'a> FnMut(&mut T, &Selector<'_>, AnyCb<'a>),
{ {
self.with(|s| s.set_call_on_any(f)) self.with(|s| s.set_call_on_any(f))
} }
@ -222,7 +222,7 @@ impl<T> Canvas<T> {
/// Sets the closure for `focus_view()`. /// Sets the closure for `focus_view()`.
pub fn set_focus_view<F>(&mut self, f: F) pub fn set_focus_view<F>(&mut self, f: F)
where where
F: 'static + FnMut(&mut T, &Selector) -> Result<(), ()>, F: 'static + FnMut(&mut T, &Selector<'_>) -> Result<(), ()>,
{ {
self.focus_view = Box::new(f); self.focus_view = Box::new(f);
} }
@ -232,14 +232,14 @@ impl<T> Canvas<T> {
/// Chainable variant. /// Chainable variant.
pub fn with_focus_view<F>(self, f: F) -> Self pub fn with_focus_view<F>(self, f: F) -> Self
where where
F: 'static + FnMut(&mut T, &Selector) -> Result<(), ()>, F: 'static + FnMut(&mut T, &Selector<'_>) -> Result<(), ()>,
{ {
self.with(|s| s.set_focus_view(f)) self.with(|s| s.set_focus_view(f))
} }
} }
impl<T: 'static> View for Canvas<T> { impl<T: 'static> View for Canvas<T> {
fn draw(&self, printer: &Printer) { fn draw(&self, printer: &Printer<'_, '_>) {
(self.draw)(&self.state, printer); (self.draw)(&self.state, printer);
} }
@ -263,7 +263,7 @@ impl<T: 'static> View for Canvas<T> {
(self.needs_relayout)(&self.state) (self.needs_relayout)(&self.state)
} }
fn focus_view(&mut self, selector: &Selector) -> Result<(), ()> { fn focus_view(&mut self, selector: &Selector<'_>) -> Result<(), ()> {
(self.focus_view)(&mut self.state, selector) (self.focus_view)(&mut self.state, selector)
} }
@ -271,7 +271,7 @@ impl<T: 'static> View for Canvas<T> {
(self.important_area)(&self.state, view_size) (self.important_area)(&self.state, view_size)
} }
fn call_on_any<'a>(&mut self, selector: &Selector, cb: AnyCb<'a>) { fn call_on_any<'a>(&mut self, selector: &Selector<'_>, cb: AnyCb<'a>) {
(self.call_on_any)(&mut self.state, selector, cb); (self.call_on_any)(&mut self.state, selector, cb);
} }
} }

View File

@ -13,7 +13,7 @@ pub struct Checkbox {
checked: bool, checked: bool,
enabled: bool, enabled: bool,
on_change: Option<Rc<Fn(&mut Cursive, bool)>>, on_change: Option<Rc<dyn Fn(&mut Cursive, bool)>>,
} }
new_default!(Checkbox); new_default!(Checkbox);
@ -96,7 +96,7 @@ impl Checkbox {
} }
} }
fn draw_internal(&self, printer: &Printer) { fn draw_internal(&self, printer: &Printer<'_, '_>) {
printer.print((0, 0), "[ ]"); printer.print((0, 0), "[ ]");
if self.checked { if self.checked {
printer.print((1, 0), "X"); printer.print((1, 0), "X");
@ -113,7 +113,7 @@ impl View for Checkbox {
self.enabled self.enabled
} }
fn draw(&self, printer: &Printer) { fn draw(&self, printer: &Printer<'_, '_>) {
if self.enabled && printer.enabled { if self.enabled && printer.enabled {
printer.with_selection(printer.focused, |printer| { printer.with_selection(printer.focused, |printer| {
self.draw_internal(printer) self.draw_internal(printer)

View File

@ -19,7 +19,7 @@ impl DebugView {
} }
impl View for DebugView { impl View for DebugView {
fn draw(&self, printer: &Printer) { fn draw(&self, printer: &Printer<'_, '_>) {
let logs = logger::LOGS.lock().unwrap(); let logs = logger::LOGS.lock().unwrap();
// Only print the last logs, so skip what doesn't fit // Only print the last logs, so skip what doesn't fit
let skipped = logs.len().saturating_sub(printer.size.y); let skipped = logs.len().saturating_sub(printer.size.y);

View File

@ -124,12 +124,12 @@ impl Dialog {
/// .unwrap(); /// .unwrap();
/// assert_eq!(text_view.get_content().source(), "Hello!"); /// assert_eq!(text_view.get_content().source(), "Hello!");
/// ``` /// ```
pub fn get_content(&self) -> &View { pub fn get_content(&self) -> &dyn View {
&*self.content.view &*self.content.view
} }
/// Gets mutable access to the content. /// Gets mutable access to the content.
pub fn get_content_mut(&mut self) -> &mut View { pub fn get_content_mut(&mut self) -> &mut dyn View {
self.invalidate(); self.invalidate();
&mut *self.content.view &mut *self.content.view
} }
@ -391,7 +391,7 @@ impl Dialog {
} }
} }
fn draw_buttons(&self, printer: &Printer) -> Option<usize> { fn draw_buttons(&self, printer: &Printer<'_, '_>) -> Option<usize> {
let mut buttons_height = 0; let mut buttons_height = 0;
// Current horizontal position of the next button we'll draw. // Current horizontal position of the next button we'll draw.
@ -439,7 +439,7 @@ impl Dialog {
Some(buttons_height) Some(buttons_height)
} }
fn draw_content(&self, printer: &Printer, buttons_height: usize) { fn draw_content(&self, printer: &Printer<'_, '_>, buttons_height: usize) {
// What do we have left? // What do we have left?
let taken = Vec2::new(0, buttons_height) let taken = Vec2::new(0, buttons_height)
+ self.borders.combined() + self.borders.combined()
@ -458,7 +458,7 @@ impl Dialog {
); );
} }
fn draw_title(&self, printer: &Printer) { fn draw_title(&self, printer: &Printer<'_, '_>) {
if !self.title.is_empty() { if !self.title.is_empty() {
let len = self.title.width(); let len = self.title.width();
if len + 4 > printer.size.x { if len + 4 > printer.size.x {
@ -521,7 +521,7 @@ impl Dialog {
} }
impl View for Dialog { impl View for Dialog {
fn draw(&self, printer: &Printer) { fn draw(&self, printer: &Printer<'_, '_>) {
// This will be the buttons_height used by the buttons. // This will be the buttons_height used by the buttons.
let buttons_height = match self.draw_buttons(printer) { let buttons_height = match self.draw_buttons(printer) {
Some(height) => height, Some(height) => height,
@ -653,11 +653,11 @@ impl View for Dialog {
} }
} }
fn call_on_any<'a>(&mut self, selector: &Selector, callback: AnyCb<'a>) { fn call_on_any<'a>(&mut self, selector: &Selector<'_>, callback: AnyCb<'a>) {
self.content.call_on_any(selector, callback); self.content.call_on_any(selector, callback);
} }
fn focus_view(&mut self, selector: &Selector) -> Result<(), ()> { fn focus_view(&mut self, selector: &Selector<'_>) -> Result<(), ()> {
self.content.focus_view(selector) self.content.focus_view(selector)
} }

View File

@ -7,7 +7,7 @@ use crate::Printer;
pub struct DummyView; pub struct DummyView;
impl View for DummyView { impl View for DummyView {
fn draw(&self, _: &Printer) {} fn draw(&self, _: &Printer<'_, '_>) {}
fn needs_relayout(&self) -> bool { fn needs_relayout(&self) -> bool {
false false

View File

@ -15,12 +15,12 @@ use crate::{Cursive, Printer, With};
/// ///
/// Arguments are the `Cursive`, current content of the input and cursor /// Arguments are the `Cursive`, current content of the input and cursor
/// position /// position
pub type OnEdit = Fn(&mut Cursive, &str, usize); pub type OnEdit = dyn Fn(&mut Cursive, &str, usize);
/// Closure type for callbacks when Enter is pressed. /// Closure type for callbacks when Enter is pressed.
/// ///
/// Arguments are the `Cursive` and the content of the input. /// Arguments are the `Cursive` and the content of the input.
pub type OnSubmit = Fn(&mut Cursive, &str); pub type OnSubmit = dyn Fn(&mut Cursive, &str);
/// Input box where the user can enter and edit text. /// Input box where the user can enter and edit text.
/// ///
@ -502,7 +502,7 @@ fn make_small_stars(length: usize) -> &'static str {
} }
impl View for EditView { impl View for EditView {
fn draw(&self, printer: &Printer) { fn draw(&self, printer: &Printer<'_, '_>) {
assert_eq!( assert_eq!(
printer.size.x, self.last_length, printer.size.x, self.last_length,
"Was promised {}, received {}", "Was promised {}, received {}",

View File

@ -35,7 +35,7 @@ impl<V: View> ViewWrapper for EnableableView<V> {
} }
} }
fn wrap_draw(&self, printer: &Printer) { fn wrap_draw(&self, printer: &Printer<'_, '_>) {
self.view.draw(&printer.enabled(self.enabled)); self.view.draw(&printer.enabled(self.enabled));
} }
} }

View File

@ -91,7 +91,7 @@ impl<V: View> ViewWrapper for HideableView<V> {
} }
fn wrap_call_on_any<'a>( fn wrap_call_on_any<'a>(
&mut self, selector: &Selector, callback: Box<FnMut(&mut Any) + 'a>, &mut self, selector: &Selector<'_>, callback: Box<FnMut(&mut dyn Any) + 'a>,
) { ) {
// We always run callbacks, even when invisible. // We always run callbacks, even when invisible.
self.view.call_on_any(selector, callback) self.view.call_on_any(selector, callback)

View File

@ -42,7 +42,7 @@ impl<V: View> IdView<V> {
} }
// Shortcut for a boxed callback (for the wrap_call_on_any method). // Shortcut for a boxed callback (for the wrap_call_on_any method).
type BoxedCallback<'a> = Box<for<'b> FnMut(&'b mut Any) + 'a>; type BoxedCallback<'a> = Box<for<'b> FnMut(&'b mut dyn Any) + 'a>;
impl<T: View + 'static> ViewWrapper for IdView<T> { impl<T: View + 'static> ViewWrapper for IdView<T> {
type V = T; type V = T;
@ -77,7 +77,7 @@ impl<T: View + 'static> ViewWrapper for IdView<T> {
// Some for<'b> weirdness here to please the borrow checker gods... // Some for<'b> weirdness here to please the borrow checker gods...
fn wrap_call_on_any<'a>( fn wrap_call_on_any<'a>(
&mut self, selector: &Selector, mut callback: BoxedCallback<'a>, &mut self, selector: &Selector<'_>, mut callback: BoxedCallback<'a>,
) { ) {
match selector { match selector {
&Selector::Id(id) if id == self.id => callback(self), &Selector::Id(id) if id == self.id => callback(self),
@ -89,7 +89,7 @@ impl<T: View + 'static> ViewWrapper for IdView<T> {
} }
} }
fn wrap_focus_view(&mut self, selector: &Selector) -> Result<(), ()> { fn wrap_focus_view(&mut self, selector: &Selector<'_>) -> Result<(), ()> {
match selector { match selector {
&Selector::Id(id) if id == self.id => Ok(()), &Selector::Id(id) if id == self.id => Ok(()),
s => self s => self

View File

@ -23,7 +23,7 @@ impl<T: View> Layer<T> {
impl<T: View> ViewWrapper for Layer<T> { impl<T: View> ViewWrapper for Layer<T> {
wrap_impl!(self.view: T); wrap_impl!(self.view: T);
fn wrap_draw(&self, printer: &Printer) { fn wrap_draw(&self, printer: &Printer<'_, '_>) {
for y in 0..printer.size.y { for y in 0..printer.size.y {
printer.print_hline((0, y), printer.size.x, " "); printer.print_hline((0, y), printer.size.x, " ");
} }

View File

@ -19,7 +19,7 @@ pub struct LinearLayout {
} }
struct Child { struct Child {
view: Box<View>, view: Box<dyn View>,
// The last result from the child's required_size // The last result from the child's required_size
// Doesn't have to be what the child actually gets. // Doesn't have to be what the child actually gets.
size: Vec2, size: Vec2,
@ -33,7 +33,7 @@ impl Child {
self.size self.size
} }
fn as_view(&self) -> &View { fn as_view(&self) -> &dyn View {
&*self.view &*self.view
} }
} }
@ -176,12 +176,12 @@ impl LinearLayout {
} }
/// Returns a reference to a child. /// Returns a reference to a child.
pub fn get_child(&self, i: usize) -> Option<&View> { pub fn get_child(&self, i: usize) -> Option<&dyn View> {
self.children.get(i).map(|child| &*child.view) self.children.get(i).map(|child| &*child.view)
} }
/// Returns a mutable reference to a child. /// Returns a mutable reference to a child.
pub fn get_child_mut(&mut self, i: usize) -> Option<&mut View> { pub fn get_child_mut(&mut self, i: usize) -> Option<&mut dyn View> {
// Anything could happen to the child view, so bust the cache. // Anything could happen to the child view, so bust the cache.
self.invalidate(); self.invalidate();
self.children.get_mut(i).map(|child| &mut *child.view) self.children.get_mut(i).map(|child| &mut *child.view)
@ -190,7 +190,7 @@ impl LinearLayout {
/// Removes a child. /// Removes a child.
/// ///
/// If `i` is within bounds, the removed child will be returned. /// If `i` is within bounds, the removed child will be returned.
pub fn remove_child(&mut self, i: usize) -> Option<Box<View>> { pub fn remove_child(&mut self, i: usize) -> Option<Box<dyn View>> {
if i < self.children.len() { if i < self.children.len() {
// Any alteration means we should invalidate the cache. // Any alteration means we should invalidate the cache.
self.invalidate(); self.invalidate();
@ -240,7 +240,7 @@ impl LinearLayout {
/// Returns a cyclic mutable iterator starting with the child in focus /// Returns a cyclic mutable iterator starting with the child in focus
fn iter_mut<'a>( fn iter_mut<'a>(
&'a mut self, from_focus: bool, source: direction::Relative, &'a mut self, from_focus: bool, source: direction::Relative,
) -> Box<Iterator<Item = (usize, &mut Child)> + 'a> { ) -> Box<dyn Iterator<Item = (usize, &mut Child)> + 'a> {
match source { match source {
direction::Relative::Front => { direction::Relative::Front => {
let start = if from_focus { self.focus } else { 0 }; let start = if from_focus { self.focus } else { 0 };
@ -334,7 +334,7 @@ fn try_focus(
} }
impl View for LinearLayout { impl View for LinearLayout {
fn draw(&self, printer: &Printer) { fn draw(&self, printer: &Printer<'_, '_>) {
// Use pre-computed sizes // Use pre-computed sizes
// debug!("Pre loop!"); // debug!("Pre loop!");
for (i, item) in ChildIterator::new( for (i, item) in ChildIterator::new(
@ -597,7 +597,7 @@ impl View for LinearLayout {
} }
fn call_on_any<'a>( fn call_on_any<'a>(
&mut self, selector: &Selector, mut callback: AnyCb<'a>, &mut self, selector: &Selector<'_>, mut callback: AnyCb<'a>,
) { ) {
for child in &mut self.children { for child in &mut self.children {
child child
@ -606,7 +606,7 @@ impl View for LinearLayout {
} }
} }
fn focus_view(&mut self, selector: &Selector) -> Result<(), ()> { fn focus_view(&mut self, selector: &Selector<'_>) -> Result<(), ()> {
for (i, child) in self.children.iter_mut().enumerate() { for (i, child) in self.children.iter_mut().enumerate() {
if child.view.focus_view(selector).is_ok() { if child.view.focus_view(selector).is_ok() {
self.focus = i; self.focus = i;

View File

@ -14,7 +14,7 @@ use crate::With;
/// [`ListView`]: struct.ListView.html /// [`ListView`]: struct.ListView.html
pub enum ListChild { pub enum ListChild {
/// A single row, with a label and a view. /// A single row, with a label and a view.
Row(String, Box<View>), Row(String, Box<dyn View>),
/// A delimiter between groups. /// A delimiter between groups.
Delimiter, Delimiter,
} }
@ -27,7 +27,7 @@ impl ListChild {
} }
} }
fn view(&mut self) -> Option<&mut View> { fn view(&mut self) -> Option<&mut dyn View> {
match *self { match *self {
ListChild::Row(_, ref mut view) => Some(view.as_mut()), ListChild::Row(_, ref mut view) => Some(view.as_mut()),
_ => None, _ => None,
@ -40,7 +40,7 @@ pub struct ListView {
children: Vec<ListChild>, children: Vec<ListChild>,
focus: usize, focus: usize,
// This callback is called when the selection is changed. // This callback is called when the selection is changed.
on_select: Option<Rc<Fn(&mut Cursive, &String)>>, on_select: Option<Rc<dyn Fn(&mut Cursive, &String)>>,
last_size: Vec2, last_size: Vec2,
} }
@ -147,7 +147,7 @@ impl ListView {
fn iter_mut<'a>( fn iter_mut<'a>(
&'a mut self, from_focus: bool, source: direction::Relative, &'a mut self, from_focus: bool, source: direction::Relative,
) -> Box<Iterator<Item = (usize, &mut ListChild)> + 'a> { ) -> Box<dyn Iterator<Item = (usize, &mut ListChild)> + 'a> {
match source { match source {
direction::Relative::Front => { direction::Relative::Front => {
let start = if from_focus { self.focus } else { 0 }; let start = if from_focus { self.focus } else { 0 };
@ -250,7 +250,7 @@ fn try_focus(
} }
impl View for ListView { impl View for ListView {
fn draw(&self, printer: &Printer) { fn draw(&self, printer: &Printer<'_, '_>) {
if self.children.is_empty() { if self.children.is_empty() {
return; return;
} }
@ -379,14 +379,14 @@ impl View for ListView {
} }
fn call_on_any<'a>( fn call_on_any<'a>(
&mut self, selector: &Selector, mut callback: AnyCb<'a>, &mut self, selector: &Selector<'_>, mut callback: AnyCb<'a>,
) { ) {
for view in self.children.iter_mut().filter_map(ListChild::view) { for view in self.children.iter_mut().filter_map(ListChild::view) {
view.call_on_any(selector, Box::new(|any| callback(any))); view.call_on_any(selector, Box::new(|any| callback(any)));
} }
} }
fn focus_view(&mut self, selector: &Selector) -> Result<(), ()> { fn focus_view(&mut self, selector: &Selector<'_>) -> Result<(), ()> {
if let Some(i) = self if let Some(i) = self
.children .children
.iter_mut() .iter_mut()

View File

@ -202,7 +202,7 @@ impl MenuPopup {
} }
impl View for MenuPopup { impl View for MenuPopup {
fn draw(&self, printer: &Printer) { fn draw(&self, printer: &Printer<'_, '_>) {
if !printer.size.fits((2, 2)) { if !printer.size.fits((2, 2)) {
return; return;
} }

View File

@ -261,7 +261,7 @@ fn show_child(s: &mut Cursive, offset: Vec2, menu: Rc<MenuTree>) {
} }
impl View for Menubar { impl View for Menubar {
fn draw(&self, printer: &Printer) { fn draw(&self, printer: &Printer<'_, '_>) {
// Draw the bar at the top // Draw the bar at the top
printer.with_color(ColorStyle::primary(), |printer| { printer.with_color(ColorStyle::primary(), |printer| {
printer.print_hline((0, 0), printer.size.x, " "); printer.print_hline((0, 0), printer.size.x, " ");

View File

@ -43,7 +43,7 @@ pub struct OnEventView<T: View> {
callbacks: Vec<(EventTrigger, Action<T>)>, callbacks: Vec<(EventTrigger, Action<T>)>,
} }
type InnerCallback<T> = Rc<Box<Fn(&mut T, &Event) -> Option<EventResult>>>; type InnerCallback<T> = Rc<Box<dyn Fn(&mut T, &Event) -> Option<EventResult>>>;
struct Action<T> { struct Action<T> {
phase: TriggerPhase, phase: TriggerPhase,

View File

@ -56,7 +56,7 @@ impl<V: View> ViewWrapper for PaddedView<V> {
self.view.on_event(event.relativized(padding)) self.view.on_event(event.relativized(padding))
} }
fn wrap_draw(&self, printer: &Printer) { fn wrap_draw(&self, printer: &Printer<'_, '_>) {
let top_left = self.margins.top_left(); let top_left = self.margins.top_left();
let bot_right = self.margins.bot_right(); let bot_right = self.margins.bot_right();
let printer = &printer.offset(top_left).shrinked(bot_right); let printer = &printer.offset(top_left).shrinked(bot_right);

View File

@ -62,7 +62,7 @@ impl<V: View> Panel<V> {
self.title_position = align; self.title_position = align;
} }
fn draw_title(&self, printer: &Printer) { fn draw_title(&self, printer: &Printer<'_, '_>) {
if !self.title.is_empty() { if !self.title.is_empty() {
let len = self.title.width(); let len = self.title.width();
if len + 4 > printer.size.x { if len + 4 > printer.size.x {
@ -102,7 +102,7 @@ impl<V: View> ViewWrapper for Panel<V> {
self.view.required_size(req) + (2, 2) self.view.required_size(req) + (2, 2)
} }
fn wrap_draw(&self, printer: &Printer) { fn wrap_draw(&self, printer: &Printer<'_, '_>) {
printer.print_box((0, 0), printer.size, true); printer.print_box((0, 0), printer.size, true);
self.draw_title(&printer); self.draw_title(&printer);

View File

@ -40,7 +40,7 @@ pub struct ProgressBar {
value: Counter, value: Counter,
color: ColorType, color: ColorType,
// TODO: use a Promise instead? // TODO: use a Promise instead?
label_maker: Box<Fn(usize, (usize, usize)) -> String>, label_maker: Box<dyn Fn(usize, (usize, usize)) -> String>,
} }
fn make_percentage(value: usize, (min, max): (usize, usize)) -> String { fn make_percentage(value: usize, (min, max): (usize, usize)) -> String {
@ -225,7 +225,7 @@ fn sub_block(extra: usize) -> &'static str {
} }
impl View for ProgressBar { impl View for ProgressBar {
fn draw(&self, printer: &Printer) { fn draw(&self, printer: &Printer<'_, '_>) {
// Now, the bar itself... // Now, the bar itself...
let available = printer.size.x; let available = printer.size.x;

View File

@ -12,7 +12,7 @@ struct SharedState<T> {
selection: usize, selection: usize,
values: Vec<Rc<T>>, values: Vec<Rc<T>>,
on_change: Option<Rc<Fn(&mut Cursive, &T)>>, on_change: Option<Rc<dyn Fn(&mut Cursive, &T)>>,
} }
impl<T> SharedState<T> { impl<T> SharedState<T> {
@ -162,7 +162,7 @@ impl<T: 'static> RadioButton<T> {
}) })
} }
fn draw_internal(&self, printer: &Printer) { fn draw_internal(&self, printer: &Printer<'_, '_>) {
printer.print((0, 0), "( )"); printer.print((0, 0), "( )");
if self.is_selected() { if self.is_selected() {
printer.print((1, 0), "X"); printer.print((1, 0), "X");
@ -193,7 +193,7 @@ impl<T: 'static> View for RadioButton<T> {
self.enabled self.enabled
} }
fn draw(&self, printer: &Printer) { fn draw(&self, printer: &Printer<'_, '_>) {
if self.enabled && printer.enabled { if self.enabled && printer.enabled {
printer.with_selection(printer.focused, |printer| { printer.with_selection(printer.focused, |printer| {
self.draw_internal(printer) self.draw_internal(printer)

View File

@ -431,7 +431,7 @@ impl<V> View for ScrollView<V>
where where
V: View, V: View,
{ {
fn draw(&self, printer: &Printer) { fn draw(&self, printer: &Printer<'_, '_>) {
// Draw scrollbar? // Draw scrollbar?
let scrolling = self.is_scrolling(); let scrolling = self.is_scrolling();
@ -692,11 +692,11 @@ where
size size
} }
fn call_on_any<'a>(&mut self, selector: &Selector, cb: AnyCb<'a>) { fn call_on_any<'a>(&mut self, selector: &Selector<'_>, cb: AnyCb<'a>) {
self.inner.call_on_any(selector, cb) self.inner.call_on_any(selector, cb)
} }
fn focus_view(&mut self, selector: &Selector) -> Result<(), ()> { fn focus_view(&mut self, selector: &Selector<'_>) -> Result<(), ()> {
self.inner.focus_view(selector) self.inner.focus_view(selector)
} }

View File

@ -59,11 +59,11 @@ pub struct SelectView<T = String> {
// This is a custom callback to include a &T. // This is a custom callback to include a &T.
// It will be called whenever "Enter" is pressed or when an item is clicked. // It will be called whenever "Enter" is pressed or when an item is clicked.
on_submit: Option<Rc<Fn(&mut Cursive, &T)>>, on_submit: Option<Rc<dyn Fn(&mut Cursive, &T)>>,
// This callback is called when the selection is changed. // This callback is called when the selection is changed.
// TODO: add the previous selection? Indices? // TODO: add the previous selection? Indices?
on_select: Option<Rc<Fn(&mut Cursive, &T)>>, on_select: Option<Rc<dyn Fn(&mut Cursive, &T)>>,
// If `true`, when a character is pressed, jump to the next item starting // If `true`, when a character is pressed, jump to the next item starting
// with this character. // with this character.
@ -347,7 +347,7 @@ impl<T: 'static> SelectView<T> {
self.with(|s| s.add_all(iter)) self.with(|s| s.add_all(iter))
} }
fn draw_item(&self, printer: &Printer, i: usize) { fn draw_item(&self, printer: &Printer<'_, '_>, i: usize) {
let l = self.items[i].label.width(); let l = self.items[i].label.width();
let x = self.align.h.get_offset(l, printer.size.x); let x = self.align.h.get_offset(l, printer.size.x);
printer.print_hline((0, 0), x, " "); printer.print_hline((0, 0), x, " ");
@ -670,7 +670,7 @@ impl SelectView<String> {
} }
impl<T: 'static> View for SelectView<T> { impl<T: 'static> View for SelectView<T> {
fn draw(&self, printer: &Printer) { fn draw(&self, printer: &Printer<'_, '_>) {
self.last_offset.set(printer.offset); self.last_offset.set(printer.offset);
if self.popup { if self.popup {

View File

@ -70,7 +70,7 @@ impl<T: View> ViewWrapper for ShadowView<T> {
self.view.on_event(event.relativized(padding)) self.view.on_event(event.relativized(padding))
} }
fn wrap_draw(&self, printer: &Printer) { fn wrap_draw(&self, printer: &Printer<'_, '_>) {
if printer.size.y <= self.top_padding as usize if printer.size.y <= self.top_padding as usize
|| printer.size.x <= self.left_padding as usize || printer.size.x <= self.left_padding as usize
{ {

View File

@ -10,8 +10,8 @@ use crate::{Cursive, Printer};
/// A horizontal or vertical slider. /// A horizontal or vertical slider.
pub struct SliderView { pub struct SliderView {
orientation: Orientation, orientation: Orientation,
on_change: Option<Rc<Fn(&mut Cursive, usize)>>, on_change: Option<Rc<dyn Fn(&mut Cursive, usize)>>,
on_enter: Option<Rc<Fn(&mut Cursive, usize)>>, on_enter: Option<Rc<dyn Fn(&mut Cursive, usize)>>,
value: usize, value: usize,
max_value: usize, max_value: usize,
dragging: bool, dragging: bool,
@ -112,7 +112,7 @@ impl SliderView {
} }
impl View for SliderView { impl View for SliderView {
fn draw(&self, printer: &Printer) { fn draw(&self, printer: &Printer<'_, '_>) {
match self.orientation { match self.orientation {
Orientation::Vertical => { Orientation::Vertical => {
printer.print_vline((0, 0), self.max_value, "|") printer.print_vline((0, 0), self.max_value, "|")

View File

@ -126,7 +126,7 @@ impl<T: View> ChildWrapper<T> {
// TODO: use macros to make this less ugly? // TODO: use macros to make this less ugly?
impl<T: View> View for ChildWrapper<T> { impl<T: View> View for ChildWrapper<T> {
fn draw(&self, printer: &Printer) { fn draw(&self, printer: &Printer<'_, '_>) {
match *self { match *self {
ChildWrapper::Shadow(ref v) => v.draw(printer), ChildWrapper::Shadow(ref v) => v.draw(printer),
ChildWrapper::Backfilled(ref v) => v.draw(printer), ChildWrapper::Backfilled(ref v) => v.draw(printer),
@ -166,7 +166,7 @@ impl<T: View> View for ChildWrapper<T> {
} }
} }
fn call_on_any<'a>(&mut self, selector: &Selector, callback: AnyCb<'a>) { fn call_on_any<'a>(&mut self, selector: &Selector<'_>, callback: AnyCb<'a>) {
match *self { match *self {
ChildWrapper::Shadow(ref mut v) => { ChildWrapper::Shadow(ref mut v) => {
v.call_on_any(selector, callback) v.call_on_any(selector, callback)
@ -180,7 +180,7 @@ impl<T: View> View for ChildWrapper<T> {
} }
} }
fn focus_view(&mut self, selector: &Selector) -> Result<(), ()> { fn focus_view(&mut self, selector: &Selector<'_>) -> Result<(), ()> {
match *self { match *self {
ChildWrapper::Shadow(ref mut v) => v.focus_view(selector), ChildWrapper::Shadow(ref mut v) => v.focus_view(selector),
ChildWrapper::Backfilled(ref mut v) => v.focus_view(selector), ChildWrapper::Backfilled(ref mut v) => v.focus_view(selector),
@ -266,14 +266,14 @@ impl StackView {
} }
/// Returns a reference to the layer at the given position. /// Returns a reference to the layer at the given position.
pub fn get(&self, pos: LayerPosition) -> Option<&View> { pub fn get(&self, pos: LayerPosition) -> Option<&dyn View> {
self.get_index(pos).and_then(|i| { self.get_index(pos).and_then(|i| {
self.layers.get(i).map(|child| &**child.view.get_inner()) self.layers.get(i).map(|child| &**child.view.get_inner())
}) })
} }
/// Returns a mutable reference to the layer at the given position. /// Returns a mutable reference to the layer at the given position.
pub fn get_mut(&mut self, pos: LayerPosition) -> Option<&mut View> { pub fn get_mut(&mut self, pos: LayerPosition) -> Option<&mut dyn View> {
self.get_index(pos).and_then(move |i| { self.get_index(pos).and_then(move |i| {
self.layers self.layers
.get_mut(i) .get_mut(i)
@ -397,13 +397,13 @@ impl StackView {
/// # Panics /// # Panics
/// ///
/// If the given position is out of bounds. /// If the given position is out of bounds.
pub fn remove_layer(&mut self, position: LayerPosition) -> Box<View> { pub fn remove_layer(&mut self, position: LayerPosition) -> Box<dyn View> {
let i = self.get_index(position).unwrap(); let i = self.get_index(position).unwrap();
self.layers.remove(i).view.unwrap().unwrap() self.layers.remove(i).view.unwrap().unwrap()
} }
/// Remove the top-most layer. /// Remove the top-most layer.
pub fn pop_layer(&mut self) -> Option<Box<View>> { pub fn pop_layer(&mut self) -> Option<Box<dyn View>> {
self.bg_dirty.set(true); self.bg_dirty.set(true);
self.layers self.layers
.pop() .pop()
@ -500,7 +500,7 @@ impl StackView {
/// ease inserting layers under the stackview but above its background. /// ease inserting layers under the stackview but above its background.
/// ///
/// you probably just want to call draw() /// you probably just want to call draw()
pub fn draw_bg(&self, printer: &Printer) { pub fn draw_bg(&self, printer: &Printer<'_, '_>) {
// If the background is dirty draw a new background // If the background is dirty draw a new background
if self.bg_dirty.get() { if self.bg_dirty.get() {
for y in 0..printer.size.y { for y in 0..printer.size.y {
@ -520,7 +520,7 @@ impl StackView {
/// ease inserting layers under the stackview but above its background. /// ease inserting layers under the stackview but above its background.
/// ///
/// You probably just want to call draw() /// You probably just want to call draw()
pub fn draw_fg(&self, printer: &Printer) { pub fn draw_fg(&self, printer: &Printer<'_, '_>) {
let last = self.layers.len(); let last = self.layers.len();
printer.with_color(ColorStyle::primary(), |printer| { printer.with_color(ColorStyle::primary(), |printer| {
for (i, (v, offset)) in for (i, (v, offset)) in
@ -585,7 +585,7 @@ where
} }
impl View for StackView { impl View for StackView {
fn draw(&self, printer: &Printer) { fn draw(&self, printer: &Printer<'_, '_>) {
// This function is included for compat with the view trait, // This function is included for compat with the view trait,
// it should behave the same as calling them seperately, but does // it should behave the same as calling them seperately, but does
// not pause to let you insert in between the layers. // not pause to let you insert in between the layers.
@ -650,7 +650,7 @@ impl View for StackView {
} }
fn call_on_any<'a>( fn call_on_any<'a>(
&mut self, selector: &Selector, mut callback: AnyCb<'a>, &mut self, selector: &Selector<'_>, mut callback: AnyCb<'a>,
) { ) {
for layer in &mut self.layers { for layer in &mut self.layers {
layer layer
@ -659,7 +659,7 @@ impl View for StackView {
} }
} }
fn focus_view(&mut self, selector: &Selector) -> Result<(), ()> { fn focus_view(&mut self, selector: &Selector<'_>) -> Result<(), ()> {
for layer in &mut self.layers { for layer in &mut self.layers {
if layer.view.focus_view(selector).is_ok() { if layer.view.focus_view(selector).is_ok() {
return Ok(()); return Ok(());

View File

@ -459,7 +459,7 @@ impl View for TextArea {
) )
} }
fn draw(&self, printer: &Printer) { fn draw(&self, printer: &Printer<'_, '_>) {
printer.with_color(ColorStyle::secondary(), |printer| { printer.with_color(ColorStyle::secondary(), |printer| {
let effect = if self.enabled && printer.enabled { let effect = if self.enabled && printer.enabled {
Effect::Reverse Effect::Reverse

View File

@ -346,7 +346,7 @@ impl TextView {
} }
impl View for TextView { impl View for TextView {
fn draw(&self, printer: &Printer) { fn draw(&self, printer: &Printer<'_, '_>) {
let h = self.rows.len(); let h = self.rows.len();
// If the content is smaller than the view, align it somewhere. // If the content is smaller than the view, align it somewhere.
let offset = self.align.v.get_offset(h, printer.size.y); let offset = self.align.v.get_offset(h, printer.size.y);

View File

@ -37,7 +37,7 @@ impl<T: View> TrackedView<T> {
impl<T: View> ViewWrapper for TrackedView<T> { impl<T: View> ViewWrapper for TrackedView<T> {
wrap_impl!(self.view: T); wrap_impl!(self.view: T);
fn wrap_draw(&self, printer: &Printer) { fn wrap_draw(&self, printer: &Printer<'_, '_>) {
self.offset.set(printer.offset); self.offset.set(printer.offset);
self.view.draw(printer); self.view.draw(printer);
} }

View File

@ -5,12 +5,12 @@ use crate::view::{IntoBoxedView, View, ViewWrapper};
/// ///
/// It derefs to the wrapped view. /// It derefs to the wrapped view.
pub struct ViewBox { pub struct ViewBox {
view: Box<View>, view: Box<dyn View>,
} }
impl ViewBox { impl ViewBox {
/// Creates a new `ViewBox` around the given boxed view. /// Creates a new `ViewBox` around the given boxed view.
pub fn new(view: Box<View>) -> Self { pub fn new(view: Box<dyn View>) -> Self {
ViewBox { view } ViewBox { view }
} }
@ -23,27 +23,27 @@ impl ViewBox {
} }
/// Returns the inner boxed view. /// Returns the inner boxed view.
pub fn unwrap(self) -> Box<View> { pub fn unwrap(self) -> Box<dyn View> {
self.view self.view
} }
} }
impl Deref for ViewBox { impl Deref for ViewBox {
type Target = View; type Target = dyn View;
fn deref(&self) -> &View { fn deref(&self) -> &dyn View {
&*self.view &*self.view
} }
} }
impl DerefMut for ViewBox { impl DerefMut for ViewBox {
fn deref_mut(&mut self) -> &mut View { fn deref_mut(&mut self) -> &mut dyn View {
&mut *self.view &mut *self.view
} }
} }
impl ViewWrapper for ViewBox { impl ViewWrapper for ViewBox {
type V = View; type V = dyn View;
fn with_view<F, R>(&self, f: F) -> Option<R> fn with_view<F, R>(&self, f: F) -> Option<R>
where where