New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Provide a basic default implementation of History
#209
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A history_infinite()
method can be a good alias for VecDeque
Unless I'm misunderstanding what you mean here, as it stands, I don't think this is possible, since the |
examples/history.rs
Outdated
@@ -9,6 +9,10 @@ fn main() { | |||
|
|||
let mut history = MyHistory::default(); | |||
|
|||
/// We can also use `Vec` or `VecDeque` directly for a simple infinite history. | |||
// let mut history = Vec::new(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you remove this line and update the comment above this line accordingly?
There is a way to implement a Also @Garbaz what do you think about it ? |
I have implemented a very similar approach, just slightly more general, with history either being owned by the So, given how the API is set up, I think the best option is to leave the I do like the idea of having some basic history features included. So instead of the implementation of |
History
Great, I like it. Thank you! We can make |
As it stands, if one wants to have an input with history, one has to define a custom struct and implement the History trait for it, which is quite some boilerplate code (See examples/history.rs). Since in most simple applications, one probably doesn't need any custom history logic (limited size / no duplicates / etc.), simply providing a default implementation for
Vec
andVecDeque
seems sensible to me.The
VecDeque
implementation is very straightforward and equivalent to the provided example, except without limiting the size. For theVec
implementation we have to index from the back, which requires checking in advance that thepos
is in bounds, since otherwise we end up subtracting ausize
below zero, which explodes.