From e033e3576f723dd858db09180e814dd60be2aded Mon Sep 17 00:00:00 2001 From: Wez Furlong Date: Wed, 8 Apr 2020 22:32:14 -0700 Subject: [PATCH] termwiz: History::get() -> Option> The BasicHistory impl returned a borrowed reference but the sqlite based impl I'm adding to wzsh needs to own it. --- termwiz/src/lineedit/history.rs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/termwiz/src/lineedit/history.rs b/termwiz/src/lineedit/history.rs index 1e3118095..e534413b2 100644 --- a/termwiz/src/lineedit/history.rs +++ b/termwiz/src/lineedit/history.rs @@ -1,3 +1,4 @@ +use std::borrow::Cow; use std::collections::VecDeque; /// Represents a position within the history. @@ -8,7 +9,7 @@ pub type HistoryIndex = usize; /// Defines the history interface for the line editor. pub trait History { /// Lookup the line corresponding to an index. - fn get(&self, idx: HistoryIndex) -> Option<&str>; + fn get(&self, idx: HistoryIndex) -> Option>; /// Return the index for the most recently added entry. fn last(&self) -> Option; /// Add an entry. @@ -24,8 +25,8 @@ pub struct BasicHistory { } impl History for BasicHistory { - fn get(&self, idx: HistoryIndex) -> Option<&str> { - self.entries.get(idx).map(String::as_str) + fn get(&self, idx: HistoryIndex) -> Option> { + self.entries.get(idx).map(|s| Cow::Borrowed(s.as_str())) } fn last(&self) -> Option {