automerge/rust/automerge/src/list_range.rs
Alex Good dd3c6d1303
Move rust workspace into ./rust
After some discussion with PVH I realise that the repo structure in the
last reorg was very rust-centric. In an attempt to put each language on
a level footing move the rust code and project files into ./rust
2022-10-16 19:55:51 +01:00

27 lines
709 B
Rust

use crate::{exid::ExId, Value};
use crate::{query, Automerge};
use std::ops::RangeBounds;
#[derive(Debug)]
pub struct ListRange<'a, R: RangeBounds<usize>> {
range: Option<query::ListRange<'a, R>>,
doc: &'a Automerge,
}
impl<'a, R: RangeBounds<usize>> ListRange<'a, R> {
pub(crate) fn new(doc: &'a Automerge, range: Option<query::ListRange<'a, R>>) -> Self {
Self { range, doc }
}
}
impl<'a, R: RangeBounds<usize>> Iterator for ListRange<'a, R> {
type Item = (usize, Value<'a>, ExId);
fn next(&mut self) -> Option<Self::Item> {
self.range
.as_mut()?
.next()
.map(|(idx, value, id)| (idx, value, self.doc.id_to_exid(id)))
}
}