From 23d65aa9dc59b5f4c7cd939a4bd7609c3943721e Mon Sep 17 00:00:00 2001 From: Alexandre Bury Date: Mon, 20 May 2019 15:45:48 -0700 Subject: [PATCH] Update examples and tutorials to Rust 2018 --- Readme.md | 2 -- doc/tutorial_1.md | 10 ---------- doc/tutorial_2.md | 8 -------- doc/tutorial_3.md | 2 -- examples/colors.rs | 2 -- examples/debug_console.rs | 15 +++++---------- examples/dialog.rs | 2 -- examples/edit.rs | 2 -- examples/hello_world.rs | 2 -- examples/key_codes.rs | 4 +--- examples/linear.rs | 2 -- examples/list_view.rs | 2 -- examples/logs.rs | 7 +------ examples/lorem.rs | 2 -- examples/markup.rs | 2 -- examples/menubar.rs | 2 -- examples/mines/main.rs | 5 +---- examples/mutation.rs | 2 -- examples/position.rs | 2 -- examples/progress.rs | 3 --- examples/radio.rs | 2 -- examples/refcell_view.rs | 2 -- examples/scroll.rs | 2 -- examples/select.rs | 2 -- examples/slider.rs | 2 -- examples/terminal_default.rs | 2 -- examples/text_area.rs | 2 -- examples/theme.rs | 2 -- examples/theme_manual.rs | 2 -- examples/vpv.rs | 3 ++- src/cursive.rs | 8 -------- src/lib.rs | 2 -- src/utils/immutify.rs | 4 +--- src/utils/lines/simple/mod.rs | 2 -- src/view/view_wrapper.rs | 10 ++++------ src/views/edit_view.rs | 1 - src/views/select_view.rs | 1 - 37 files changed, 15 insertions(+), 112 deletions(-) diff --git a/Readme.md b/Readme.md index 0c1ff4e..da33ecf 100644 --- a/Readme.md +++ b/Readme.md @@ -30,8 +30,6 @@ cursive = { git = "https://github.com/gyscos/Cursive" } ([You will also need ncurses installed.](https://github.com/gyscos/Cursive/wiki/Install-ncurses)) ```rust,no_run -extern crate cursive; - use cursive::Cursive; use cursive::views::{Dialog, TextView}; diff --git a/doc/tutorial_1.md b/doc/tutorial_1.md index 0d8c5ca..94b5699 100644 --- a/doc/tutorial_1.md +++ b/doc/tutorial_1.md @@ -6,8 +6,6 @@ In this first tutorial, we'll learn the basics of cursive, and write a very basic first application: ```rust,no_run -extern crate cursive; - use cursive::Cursive; use cursive::views::TextView; @@ -51,8 +49,6 @@ cursive = "*" Finally, update `src/main.rs` to import it: ```rust,no_run -extern crate cursive; - fn main() { } ``` @@ -75,8 +71,6 @@ so let's skip it for now. In its simplest form, a cursive application is therefore: ```rust,no_run -extern crate cursive; - use cursive::Cursive; fn main() { @@ -112,8 +106,6 @@ This method takes 2 arguments: a trigger, and a callback. In the end, we have: ```rust,no_run -extern crate cursive; - use cursive::Cursive; fn main() { @@ -153,8 +145,6 @@ exactly that. Once we've added this line, our first application is complete: ```rust,no_run -extern crate cursive; - use cursive::Cursive; use cursive::views::TextView; diff --git a/doc/tutorial_2.md b/doc/tutorial_2.md index cd4b731..ae26893 100644 --- a/doc/tutorial_2.md +++ b/doc/tutorial_2.md @@ -6,8 +6,6 @@ This time, we'll work on a slightly bigger example, where the user will need to actually make some choices. Here is what the code will look like: ```rust,no_run -extern crate cursive; - use cursive::Cursive; use cursive::views::Dialog; @@ -46,8 +44,6 @@ This time you're not a beginner anymore, so we'll skip the introduction! Let's start from a basic cursive application: ```rust,no_run -extern crate cursive; - use cursive::Cursive; fn main() { @@ -67,8 +63,6 @@ and/or buttons. `TextView`: ```rust,no_run -extern crate cursive; - use cursive::Cursive; use cursive::views::Dialog; use cursive::views::TextView; @@ -129,8 +123,6 @@ packing everything into the closure, let's use a separate function for the callback. Here is the current state: ```rust,no_run -extern crate cursive; - use cursive::Cursive; use cursive::views::Dialog; diff --git a/doc/tutorial_3.md b/doc/tutorial_3.md index 0a0213f..0126787 100644 --- a/doc/tutorial_3.md +++ b/doc/tutorial_3.md @@ -9,8 +9,6 @@ them to update them. Here is the code we'll end up with: ```rust,no_run -extern crate cursive; - use cursive::Cursive; use cursive::views::{Button, Dialog, DummyView, EditView, LinearLayout, SelectView}; diff --git a/examples/colors.rs b/examples/colors.rs index d1e0e00..a385f38 100644 --- a/examples/colors.rs +++ b/examples/colors.rs @@ -1,5 +1,3 @@ -extern crate cursive; - use cursive::theme::{Color, ColorStyle}; use cursive::view::Boxable; use cursive::views::Canvas; diff --git a/examples/debug_console.rs b/examples/debug_console.rs index 9f1fdcf..1ff9eae 100644 --- a/examples/debug_console.rs +++ b/examples/debug_console.rs @@ -1,24 +1,19 @@ -extern crate cursive; - -#[macro_use] -extern crate log; - fn main() { // Initialize the cursive logger. cursive::logger::init(); // Use some logging macros from the `log` crate. - error!("Something serious probably happened!"); - warn!("Or did it?"); - debug!("Logger initialized."); - info!("Starting!"); + log::error!("Something serious probably happened!"); + log::warn!("Or did it?"); + log::debug!("Logger initialized."); + log::info!("Starting!"); let mut siv = cursive::Cursive::default(); siv.add_layer(cursive::views::Dialog::text("Press ~ to open the console.\nPress l to generate logs.\nPress q to quit.")); siv.add_global_callback('q', cursive::Cursive::quit); siv.add_global_callback('~', cursive::Cursive::toggle_debug_console); - siv.add_global_callback('l', |_| trace!("Wooo")); + siv.add_global_callback('l', |_| log::trace!("Wooo")); siv.run(); } diff --git a/examples/dialog.rs b/examples/dialog.rs index f09386e..4255112 100644 --- a/examples/dialog.rs +++ b/examples/dialog.rs @@ -1,5 +1,3 @@ -extern crate cursive; - use cursive::views::{CircularFocus, Dialog, TextView}; use cursive::Cursive; diff --git a/examples/edit.rs b/examples/edit.rs index 3f5c8b8..e7429c9 100644 --- a/examples/edit.rs +++ b/examples/edit.rs @@ -1,5 +1,3 @@ -extern crate cursive; - use cursive::traits::*; use cursive::views::{Dialog, EditView, TextView}; use cursive::Cursive; diff --git a/examples/hello_world.rs b/examples/hello_world.rs index e0ba7c6..0ec8a08 100644 --- a/examples/hello_world.rs +++ b/examples/hello_world.rs @@ -1,5 +1,3 @@ -extern crate cursive; - use cursive::views::TextView; use cursive::Cursive; diff --git a/examples/key_codes.rs b/examples/key_codes.rs index eb4e089..9d876c2 100644 --- a/examples/key_codes.rs +++ b/examples/key_codes.rs @@ -1,5 +1,3 @@ -extern crate cursive; - use cursive::event::{Event, EventResult}; use cursive::traits::*; use cursive::{Cursive, Printer}; @@ -24,7 +22,7 @@ impl KeyCodeView { fn new(size: usize) -> Self { KeyCodeView { history: Vec::new(), - size: size, + size, } } } diff --git a/examples/linear.rs b/examples/linear.rs index 5929501..7e61713 100644 --- a/examples/linear.rs +++ b/examples/linear.rs @@ -1,5 +1,3 @@ -extern crate cursive; - use cursive::align::HAlign; use cursive::traits::*; use cursive::views::{Dialog, DummyView, LinearLayout, TextView}; diff --git a/examples/list_view.rs b/examples/list_view.rs index 8780aa2..2fc6fb4 100644 --- a/examples/list_view.rs +++ b/examples/list_view.rs @@ -1,5 +1,3 @@ -extern crate cursive; - use cursive::traits::*; use cursive::views::{ Checkbox, Dialog, EditView, LinearLayout, ListView, SelectView, TextView, diff --git a/examples/logs.rs b/examples/logs.rs index c710b0c..88f5337 100644 --- a/examples/logs.rs +++ b/examples/logs.rs @@ -1,5 +1,3 @@ -extern crate cursive; - use cursive::traits::*; use cursive::vec::Vec2; use cursive::{Cursive, Printer}; @@ -65,10 +63,7 @@ impl BufferView { fn new(size: usize, rx: mpsc::Receiver) -> Self { let mut buffer = VecDeque::new(); buffer.resize(size, String::new()); - BufferView { - rx: rx, - buffer: buffer, - } + BufferView { rx, buffer } } // Reads available data from the stream into the buffer diff --git a/examples/lorem.rs b/examples/lorem.rs index dd4b4fc..5e38959 100644 --- a/examples/lorem.rs +++ b/examples/lorem.rs @@ -1,5 +1,3 @@ -extern crate cursive; - use cursive::align::HAlign; use cursive::view::Scrollable; use cursive::views::{Dialog, Panel, TextView}; diff --git a/examples/markup.rs b/examples/markup.rs index 4ea2e61..b3544bd 100644 --- a/examples/markup.rs +++ b/examples/markup.rs @@ -1,5 +1,3 @@ -extern crate cursive; - use cursive::theme::BaseColor; use cursive::theme::Color; use cursive::theme::Effect; diff --git a/examples/menubar.rs b/examples/menubar.rs index da38cfd..621c168 100644 --- a/examples/menubar.rs +++ b/examples/menubar.rs @@ -1,5 +1,3 @@ -extern crate cursive; - use cursive::event::Key; use cursive::menu::MenuTree; use cursive::traits::*; diff --git a/examples/mines/main.rs b/examples/mines/main.rs index 4cf4235..0da4435 100644 --- a/examples/mines/main.rs +++ b/examples/mines/main.rs @@ -1,6 +1,3 @@ -extern crate cursive; -extern crate rand; - mod game; use cursive::direction::Direction; @@ -148,7 +145,7 @@ impl BoardView { } } } - return EventResult::Consumed(None); + EventResult::Consumed(None) } fn auto_reveal(&mut self, pos: Vec2) -> EventResult { diff --git a/examples/mutation.rs b/examples/mutation.rs index 32cf39b..2947cf9 100644 --- a/examples/mutation.rs +++ b/examples/mutation.rs @@ -1,5 +1,3 @@ -extern crate cursive; - use cursive::traits::*; use cursive::view::{Offset, Position}; use cursive::views::{Dialog, OnEventView, TextView}; diff --git a/examples/position.rs b/examples/position.rs index 1219146..1703a88 100644 --- a/examples/position.rs +++ b/examples/position.rs @@ -1,5 +1,3 @@ -extern crate cursive; - use cursive::view::Position; use cursive::views::LayerPosition; use cursive::views::TextView; diff --git a/examples/progress.rs b/examples/progress.rs index 9a93898..b6a5b3f 100644 --- a/examples/progress.rs +++ b/examples/progress.rs @@ -1,6 +1,3 @@ -extern crate cursive; -extern crate rand; - use cursive::traits::*; use cursive::utils::Counter; use cursive::views::{Button, Dialog, LinearLayout, ProgressBar, TextView}; diff --git a/examples/radio.rs b/examples/radio.rs index 5435900..ab6c268 100644 --- a/examples/radio.rs +++ b/examples/radio.rs @@ -1,5 +1,3 @@ -extern crate cursive; - use cursive::views::{Dialog, DummyView, LinearLayout, RadioGroup}; use cursive::Cursive; diff --git a/examples/refcell_view.rs b/examples/refcell_view.rs index 827e781..a2abf16 100644 --- a/examples/refcell_view.rs +++ b/examples/refcell_view.rs @@ -1,5 +1,3 @@ -extern crate cursive; - use cursive::view::{Boxable, Identifiable}; use cursive::views::{Dialog, EditView, LinearLayout, TextView}; use cursive::Cursive; diff --git a/examples/scroll.rs b/examples/scroll.rs index 4a2c5a5..037aca8 100644 --- a/examples/scroll.rs +++ b/examples/scroll.rs @@ -1,5 +1,3 @@ -extern crate cursive; - use cursive::traits::Boxable; use cursive::view::Scrollable; use cursive::views::{Button, Canvas, Dialog, LinearLayout}; diff --git a/examples/select.rs b/examples/select.rs index 3090cec..521aaf4 100644 --- a/examples/select.rs +++ b/examples/select.rs @@ -1,5 +1,3 @@ -extern crate cursive; - use cursive::align::HAlign; use cursive::event::EventResult; use cursive::traits::*; diff --git a/examples/slider.rs b/examples/slider.rs index 1ad4f4f..70b5978 100644 --- a/examples/slider.rs +++ b/examples/slider.rs @@ -1,5 +1,3 @@ -extern crate cursive; - use cursive::traits::*; use cursive::views::{Dialog, SliderView}; use cursive::Cursive; diff --git a/examples/terminal_default.rs b/examples/terminal_default.rs index eb96433..00de7fb 100644 --- a/examples/terminal_default.rs +++ b/examples/terminal_default.rs @@ -1,5 +1,3 @@ -extern crate cursive; - use cursive::theme::{Color, PaletteColor, Theme}; use cursive::views::TextView; use cursive::Cursive; diff --git a/examples/text_area.rs b/examples/text_area.rs index ea162c2..34bf739 100644 --- a/examples/text_area.rs +++ b/examples/text_area.rs @@ -1,5 +1,3 @@ -extern crate cursive; - use cursive::event::{Event, Key}; use cursive::traits::*; use cursive::views::{Dialog, EditView, OnEventView, TextArea}; diff --git a/examples/theme.rs b/examples/theme.rs index 2793b3c..30d3506 100644 --- a/examples/theme.rs +++ b/examples/theme.rs @@ -1,5 +1,3 @@ -extern crate cursive; - use cursive::views::{Dialog, TextView}; use cursive::Cursive; diff --git a/examples/theme_manual.rs b/examples/theme_manual.rs index 80e99a1..7dbb6b8 100644 --- a/examples/theme_manual.rs +++ b/examples/theme_manual.rs @@ -1,5 +1,3 @@ -extern crate cursive; - use cursive::theme::{BaseColor, BorderStyle, Color, ColorStyle}; use cursive::views::{Dialog, EditView, LinearLayout, TextView}; use cursive::Cursive; diff --git a/examples/vpv.rs b/examples/vpv.rs index 7c6d521..7f63bbb 100644 --- a/examples/vpv.rs +++ b/examples/vpv.rs @@ -47,7 +47,8 @@ fn main() { let duration = now - start; let seconds = duration.as_secs() as f64 - + duration.subsec_nanos() as f64 * 1e-9; + + f64::from(duration.subsec_nanos()) + * 1e-9; let speed = ticks / seconds; diff --git a/src/cursive.rs b/src/cursive.rs index c71d8a2..d9380f5 100644 --- a/src/cursive.rs +++ b/src/cursive.rs @@ -325,7 +325,6 @@ impl Cursive { /// # Examples /// /// ```rust - /// # extern crate cursive; /// # use cursive::*; /// # fn main() { /// let mut siv = Cursive::dummy(); @@ -358,8 +357,6 @@ impl Cursive { /// # Examples /// /// ```rust - /// # extern crate cursive; - /// # /// # use cursive::{Cursive, event}; /// # use cursive::views::{Dialog}; /// # use cursive::traits::*; @@ -512,7 +509,6 @@ impl Cursive { /// # Examples /// /// ```rust - /// # extern crate cursive; /// # use cursive::{Cursive, views, view}; /// # use cursive::traits::*; /// # fn main() { @@ -550,7 +546,6 @@ impl Cursive { /// # Examples /// /// ```rust - /// # extern crate cursive; /// # use cursive::{Cursive, views}; /// # use cursive::traits::*; /// # fn main() { @@ -645,7 +640,6 @@ impl Cursive { /// # Examples /// /// ```rust - /// # extern crate cursive; /// # use cursive::*; /// # fn main() { /// let mut siv = Cursive::dummy(); @@ -668,7 +662,6 @@ impl Cursive { /// # Examples /// /// ```rust - /// # extern crate cursive; /// # use cursive::*; /// # fn main() { /// let mut siv = Cursive::dummy(); @@ -690,7 +683,6 @@ impl Cursive { /// # Examples /// /// ```rust - /// # extern crate cursive; /// # use cursive::*; /// # fn main() { /// let mut siv = Cursive::dummy(); diff --git a/src/lib.rs b/src/lib.rs index be0e0b5..45f5eaa 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -33,8 +33,6 @@ //! ## Examples //! //! ```rust -//! extern crate cursive; -//! //! use cursive::Cursive; //! use cursive::views::TextView; //! diff --git a/src/utils/immutify.rs b/src/utils/immutify.rs index 72903ad..a93dbe1 100644 --- a/src/utils/immutify.rs +++ b/src/utils/immutify.rs @@ -52,9 +52,7 @@ pub fn immutify( /// # Examples /// /// ```rust -/// # #[macro_use] -/// # extern crate cursive; -/// # use cursive::Cursive; +/// # use cursive::{Cursive, immut1}; /// # fn main() { /// # let mut siv = Cursive::dummy(); /// let mut i = 0; diff --git a/src/utils/lines/simple/mod.rs b/src/utils/lines/simple/mod.rs index 32eb7e1..7e3ed06 100644 --- a/src/utils/lines/simple/mod.rs +++ b/src/utils/lines/simple/mod.rs @@ -39,8 +39,6 @@ pub fn make_lines(content: &str, width: usize) -> Vec { /// Example: /// /// ``` -/// # extern crate cursive; -/// extern crate unicode_segmentation; /// use unicode_segmentation::UnicodeSegmentation; /// /// # use cursive::utils::lines::simple::prefix; diff --git a/src/view/view_wrapper.rs b/src/view/view_wrapper.rs index 898389e..cd02340 100644 --- a/src/view/view_wrapper.rs +++ b/src/view/view_wrapper.rs @@ -154,14 +154,13 @@ impl View for T { /// # Examples /// /// ```rust -/// # #[macro_use] extern crate cursive; /// # use cursive::view::{View,ViewWrapper}; /// struct FooView { /// view: T, /// } /// /// impl ViewWrapper for FooView { -/// wrap_impl!(self.view: T); +/// cursive::wrap_impl!(self.view: T); /// } /// # fn main() { } /// ``` @@ -199,18 +198,17 @@ macro_rules! wrap_impl { /// # Examples /// /// ```rust -/// # #[macro_use] extern crate cursive; -/// # use cursive::view::{View,ViewWrapper}; +/// # use cursive::view::{View, ViewWrapper}; /// struct FooView { /// view: T, /// } /// /// impl FooView { -/// inner_getters!(self.view: T); +/// cursive::inner_getters!(self.view: T); /// } /// /// impl ViewWrapper for FooView { -/// wrap_impl!(self.view: T); +/// cursive::wrap_impl!(self.view: T); /// } /// # fn main() { } /// ``` diff --git a/src/views/edit_view.rs b/src/views/edit_view.rs index 4880128..6726754 100644 --- a/src/views/edit_view.rs +++ b/src/views/edit_view.rs @@ -31,7 +31,6 @@ pub type OnSubmit = dyn Fn(&mut Cursive, &str); /// [1]: https://github.com/gyscos/Cursive/blob/master/examples/edit.rs /// /// ```rust -/// # extern crate cursive; /// # use cursive::Cursive; /// # use cursive::traits::*; /// # use cursive::views::{Dialog, EditView, TextView}; diff --git a/src/views/select_view.rs b/src/views/select_view.rs index b8fdc15..254976b 100644 --- a/src/views/select_view.rs +++ b/src/views/select_view.rs @@ -25,7 +25,6 @@ use std::rc::Rc; /// # Examples /// /// ```rust -/// # extern crate cursive; /// # use cursive::Cursive; /// # use cursive::views::{SelectView, Dialog, TextView}; /// # use cursive::align::HAlign;