diff options
author | Klas Segeljakt <klasseg@kth.se> | 2023-06-25 00:09:40 +0200 |
---|---|---|
committer | Klas Segeljakt <klasseg@kth.se> | 2023-06-25 00:13:56 +0200 |
commit | 71c2316abb591a033fd36b7e802203d690db2128 (patch) | |
tree | 3d774341235c0020be2aebd95a6efdc153869030 | |
parent | 23cb8a16135dd885a356cc243d3a8cd0da0ef0e6 (diff) | |
download | rustyline-71c2316abb591a033fd36b7e802203d690db2128.zip |
Derive Default for HistoryHinter
-rw-r--r-- | examples/custom_key_bindings.rs | 2 | ||||
-rw-r--r-- | examples/example.rs | 2 | ||||
-rw-r--r-- | 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::<MyHelper, DefaultHistory>::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; |