Skip to main content

keepass/db/types/
history.rs

1use crate::db::Entry;
2
3/// An entry's history
4#[derive(Debug, Default, Eq, PartialEq, Clone)]
5#[cfg_attr(feature = "serialization", derive(serde::Serialize))]
6pub struct History {
7    pub(crate) entries: Vec<Entry>,
8}
9
10impl History {
11    /// Add a new entry to the history
12    pub fn add_entry(&mut self, mut entry: Entry) {
13        // DISCUSS: should we make sure that the last modification time is not the same
14        // or older than the entry at the top of the history?
15
16        // Remove the history from the new history entry to avoid having
17        // an exponential number of history entries.
18        entry.history.take();
19
20        self.entries.insert(0, entry);
21    }
22
23    /// Get the history entries
24    pub fn get_entries(&self) -> &Vec<Entry> {
25        &self.entries
26    }
27}