From c857f586ab935f194ec4056691cc714a0f24dacc Mon Sep 17 00:00:00 2001
From: gwenn <gtreguier@gmail.com>
Date: Sun, 27 Nov 2016 12:03:28 +0100
Subject: [PATCH] Introduce with_config construstor to ease migration

---
 examples/example.rs |  2 +-
 src/history.rs      | 14 ++++++++------
 src/lib.rs          | 19 ++++++++++---------
 3 files changed, 19 insertions(+), 16 deletions(-)

diff --git a/examples/example.rs b/examples/example.rs
index 2ebea5dc..e97650ce 100644
--- a/examples/example.rs
+++ b/examples/example.rs
@@ -19,7 +19,7 @@ fn main() {
         .completion_type(CompletionType::List)
         .build();
     let c = FilenameCompleter::new();
-    let mut rl = Editor::new(config);
+    let mut rl = Editor::with_config(config);
     rl.set_completer(Some(c));
     if rl.load_history("history.txt").is_err() {
         println!("No previous history.");
diff --git a/src/history.rs b/src/history.rs
index 1f889162..1de12443 100644
--- a/src/history.rs
+++ b/src/history.rs
@@ -29,7 +29,10 @@ pub struct History {
 }
 
 impl History {
-    pub fn new(config: Config) -> History {
+    pub fn new() -> History {
+        Self::with_config(Config::default())
+    }
+    pub fn with_config(config: Config) -> History {
         History {
             entries: VecDeque::new(),
             max_len: config.max_history_size(),
@@ -228,7 +231,7 @@ mod tests {
     use super::{Direction, History};
 
     fn init() -> History {
-        let mut history = History::new(Config::default());
+        let mut history = History::new();
         assert!(history.add("line1"));
         assert!(history.add("line2"));
         assert!(history.add("line3"));
@@ -237,9 +240,7 @@ mod tests {
 
     #[test]
     fn new() {
-        let config = Config::default();
-        let history = History::new(config);
-        assert_eq!(config.max_history_size(), history.max_len);
+        let history = History::new();
         assert_eq!(0, history.entries.len());
     }
 
@@ -248,7 +249,8 @@ mod tests {
         let config = Config::builder()
             .history_ignore_space(true)
             .build();
-        let mut history = History::new(config);
+        let mut history = History::with_config(config);
+        assert_eq!(config.max_history_size(), history.max_len);
         assert!(history.add("line1"));
         assert!(history.add("line2"));
         assert!(!history.add("line2"));
diff --git a/src/lib.rs b/src/lib.rs
index 952ddcd3..59ae361f 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -7,8 +7,7 @@
 //! Usage
 //!
 //! ```
-//! let config = rustyline::Config::default();
-//! let mut rl = rustyline::Editor::<()>::new(config);
+//! let mut rl = rustyline::Editor::<()>::new();
 //! let readline = rl.readline(">> ");
 //! match readline {
 //!     Ok(line) => println!("Line: {:?}",line),
@@ -1061,11 +1060,15 @@ pub struct Editor<C: Completer> {
 }
 
 impl<C: Completer> Editor<C> {
-    pub fn new(config: Config) -> Editor<C> {
+    pub fn new() -> Editor<C> {
+        Self::with_config(Config::default())
+    }
+
+    pub fn with_config(config: Config) -> Editor<C> {
         let term = Terminal::new();
         Editor {
             term: term,
-            history: History::new(config),
+            history: History::with_config(config),
             completer: None,
             kill_ring: KillRing::new(60),
             config: config,
@@ -1115,8 +1118,7 @@ impl<C: Completer> Editor<C> {
     }
 
     /// ```
-    /// let config = rustyline::Config::default();
-    /// let mut rl = rustyline::Editor::<()>::new(config);
+    /// let mut rl = rustyline::Editor::<()>::new();
     /// for readline in rl.iter("> ") {
     ///     match readline {
     ///         Ok(line) => {
@@ -1203,8 +1205,7 @@ mod test {
     }
 
     fn init_editor(keys: &[KeyPress]) -> Editor<()> {
-        let config = Config::default();
-        let mut editor = Editor::<()>::new(config);
+        let mut editor = Editor::<()>::new();
         editor.term.keys.extend(keys.iter().cloned());
         editor
     }
@@ -1214,7 +1215,7 @@ mod test {
         let mut out = ::std::io::sink();
         let line = "current edited line";
         let mut s = init_state(&mut out, line, 6, 80);
-        let mut history = History::new(Config::default());
+        let mut history = History::new();
         history.add("line0");
         history.add("line1");
         s.history_index = history.len();
-- 
GitLab