LSM3P7VKAWMCE4VP5F6MU72N6JSSBUX5W5ITE54Z7WSQRUVU2SRQC
pub fn changes<T>(&self, txn: &GenericTxn<T>) -> Result<Vec<(u64, ChangeHash)>, Error>
/// Iterator over the changes in this document, in the order they were
/// applied (i.e. oldest first).
pub fn changes<'a, T>(
&'a self,
txn: &'a GenericTxn<T>,
) -> Changes<'a, T, impl BTreePage<L64, StoredHash>>
Ok(changes)
/// Iterator over the changes in this document, in reverse order (i.e.
/// newest first).
pub fn rev_changes<'a, T>(
&'a self,
txn: &'a GenericTxn<T>,
) -> RevChanges<'a, T, impl BTreePage<L64, StoredHash>>
where
T: sanakirja::LoadPage<Error = sanakirja::Error>,
{
RevChanges {
inner: Some(btree::rev_iter(&txn.txn, &self.changes, None)),
}
let last = if let Some(max) = btree::rev_iter(&txn.txn, &self.changes, None)?.next() {
self.extend_with(txn, Some(change))
}
/// Record a series of changes to the document.
pub fn extend_with<T, I>(&mut self, txn: &mut MutTxn<T>, changes: I) -> Result<(), Error>
where
I: IntoIterator<Item = ChangeHash>,
{
let mut last = if let Some(max) = btree::rev_iter(&txn.txn, &self.changes, None)?.next() {
}
/// Iterator over the changes in a [`Doc`] in the order they were applied.
///
/// Created by [`Doc::changes`].
#[must_use = "iterators are lazy and do nothing unless consumed"]
pub struct Changes<'a, T, P>
where
T: sanakirja::LoadPage,
P: BTreePage<L64, StoredHash>,
{
inner: Option<Result<btree::Iter<'a, T, L64, StoredHash, P>, sanakirja::Error>>,
impl<'a, T, P> Iterator for Changes<'a, T, P>
where
T: sanakirja::LoadPage<Error = sanakirja::Error>,
P: BTreePage<L64, StoredHash> + 'a,
{
type Item = Result<(u64, ChangeHash), Error>;
fn next(&mut self) -> Option<Self::Item> {
let inner = self.inner.take()?;
inner.map_or_else(
|e| Some(Err(e.into())),
|mut iter| {
iter.next().map(|page| {
let x = page
.map_err(Into::into)
.map(|(t, hash)| (t.0, ChangeHash::from(*hash)));
self.inner = Some(Ok(iter));
x
})
},
)
}
}
/// Iterator over the changes in a [`Doc`] in reverse order (newest first).
///
/// Created by [`Doc::rev_iter`].
#[must_use = "iterators are lazy and do nothing unless consumed"]
pub struct RevChanges<'a, T, P>
where
T: sanakirja::LoadPage,
P: BTreePage<L64, StoredHash>,
{
inner: Option<Result<btree::RevIter<'a, T, L64, StoredHash, P>, sanakirja::Error>>,
}
impl<'a, T, P> Iterator for RevChanges<'a, T, P>
where
T: sanakirja::LoadPage<Error = sanakirja::Error>,
P: BTreePage<L64, StoredHash> + 'a,
{
type Item = Result<(u64, ChangeHash), Error>;
fn next(&mut self) -> Option<Self::Item> {
let inner = self.inner.take()?;
inner.map_or_else(
|e| Some(Err(e.into())),
|mut iter| {
iter.next().map(|page| {
let x = page
.map_err(Into::into)
.map(|(t, hash)| (t.0, ChangeHash::from(*hash)));
self.inner = Some(Ok(iter));
x
})
},
)
}
}