From 71c2316abb591a033fd36b7e802203d690db2128 Mon Sep 17 00:00:00 2001 From: Klas Segeljakt Date: Sun, 25 Jun 2023 00:09:40 +0200 Subject: Derive Default for HistoryHinter --- examples/custom_key_bindings.rs | 2 +- examples/example.rs | 2 +- src/hint.rs | 8 ++++++++ 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/examples/custom_key_bindings.rs b/examples/custom_key_bindings.rs index 3fa4519..78db874 100644 --- a/examples/custom_key_bindings.rs +++ b/examples/custom_key_bindings.rs @@ -87,7 +87,7 @@ impl ConditionalEventHandler for TabEventHandler { fn main() -> Result<()> { let mut rl = Editor::::new()?; - rl.set_helper(Some(MyHelper(HistoryHinter {}))); + rl.set_helper(Some(MyHelper(HistoryHinter::new()))); let ceh = Box::new(CompleteHintHandler); rl.bind_sequence(KeyEvent::ctrl('E'), EventHandler::Conditional(ceh.clone())); diff --git a/examples/example.rs b/examples/example.rs index fc53106..8ed975b 100644 --- a/examples/example.rs +++ b/examples/example.rs @@ -58,7 +58,7 @@ fn main() -> rustyline::Result<()> { let h = MyHelper { completer: FilenameCompleter::new(), highlighter: MatchingBracketHighlighter::new(), - hinter: HistoryHinter {}, + hinter: HistoryHinter::new(), colored_prompt: "".to_owned(), validator: MatchingBracketValidator::new(), }; diff --git a/src/hint.rs b/src/hint.rs index ea28ca8..1b4f88a 100644 --- a/src/hint.rs +++ b/src/hint.rs @@ -50,8 +50,16 @@ impl<'r, H: ?Sized + Hinter> Hinter for &'r H { /// Add suggestion based on previous history entries matching current user /// input. +#[derive(Default)] pub struct HistoryHinter {} +impl HistoryHinter { + /// Create a new `HistoryHinter` + pub fn new() -> HistoryHinter { + HistoryHinter::default() + } +} + impl Hinter for HistoryHinter { type Hint = String; -- cgit v1.2.3