~dkellner/chronofold

4ed0090e6240b71874d030a78759766194579c21 — Dominik Kellner 3 years ago 5e05ed6
Fix Clippy warnings
6 files changed, 22 insertions(+), 27 deletions(-)

M src/internal.rs
M src/iter.rs
M src/lib.rs
M src/session.rs
M src/version.rs
M tests/serialization.rs
M src/internal.rs => src/internal.rs +6 -6
@@ 1,6 1,6 @@
use crate::index::{IndexShift, RelativeNextIndex};
use crate::offsetmap::Offset;
use crate::{Author, Change, Chronofold, ChronofoldError, LogIndex, Timestamp};
use crate::{Author, Change, Chronofold, LogIndex, Timestamp};

use std::matches;



@@ 55,7 55,7 @@ impl<A: Author, T> Chronofold<A, T> {
        id: Timestamp<A>,
        reference: Option<LogIndex>,
        change: Change<T>,
    ) -> Result<LogIndex, ChronofoldError<A, T>> {
    ) -> LogIndex {
        // Find the predecessor to `op`.
        let predecessor = self.find_predecessor(id, reference, &change);



@@ 82,7 82,7 @@ impl<A: Author, T> Chronofold<A, T> {
        // Increment version.
        self.version.inc(&id);

        Ok(new_index)
        new_index
    }

    /// Applies consecutive local changes.


@@ 96,7 96,7 @@ impl<A: Author, T> Chronofold<A, T> {
        author: A,
        reference: Option<LogIndex>,
        changes: I,
    ) -> Result<Option<LogIndex>, ChronofoldError<A, T>>
    ) -> Option<LogIndex>
    where
        I: IntoIterator<Item = Change<T>>,
    {


@@ 146,9 146,9 @@ impl<A: Author, T> Chronofold<A, T> {
        if let (Some(id), Some(next_index)) = (last_id, last_next_index) {
            self.next_indices.set(id.0, next_index);
            self.version.inc(&id);
            Ok(Some(id.0))
            Some(id.0)
        } else {
            Ok(None)
            None
        }
    }


M src/iter.rs => src/iter.rs +2 -5
@@ 9,7 9,7 @@ impl<A: Author, T> Chronofold<A, T> {
    ///
    /// TODO: The name is a bit unwieldy. I'm reluctant to add it to the public
    /// API before giving it more thought.
    pub(crate) fn iter_log_indices_causal_range<'a, R>(&'a self, range: R) -> CausalIter<'a, A, T>
    pub(crate) fn iter_log_indices_causal_range<R>(&self, range: R) -> CausalIter<'_, A, T>
    where
        R: RangeBounds<LogIndex>,
    {


@@ 33,10 33,7 @@ impl<A: Author, T> Chronofold<A, T> {
    /// Returns an iterator over a subtree.
    ///
    /// The first item is always `root`.
    pub(crate) fn iter_subtree<'a>(
        &'a self,
        root: LogIndex,
    ) -> impl Iterator<Item = LogIndex> + 'a {
    pub(crate) fn iter_subtree(&self, root: LogIndex) -> impl Iterator<Item = LogIndex> + '_ {
        let mut subtree: HashSet<LogIndex> = HashSet::new();
        self.iter_log_indices_causal_range(..)
            .filter_map(move |(_, idx)| {

M src/lib.rs => src/lib.rs +8 -4
@@ 190,12 190,16 @@ impl<A: Author, T> Chronofold<A, T> {
        // with log indices.
        match op.reference {
            Some(t) => match self.log_index(&t) {
                Some(reference) => self
                    .apply_change(op.id, Some(reference), op.change)
                    .map(|_| ()),
                Some(reference) => {
                    self.apply_change(op.id, Some(reference), op.change);
                    Ok(())
                }
                None => Err(ChronofoldError::UnknownReference(op)),
            },
            None => self.apply_change(op.id, None, op.change).map(|_| ()),
            None => {
                self.apply_change(op.id, None, op.change);
                Ok(())
            }
        }
    }
}

M src/session.rs => src/session.rs +1 -5
@@ 101,10 101,7 @@ impl<'a, A: Author, T> Session<'a, A, T> {
        for idx in to_remove.into_iter() {
            self.remove(idx);
        }
        self.apply_changes(
            last_idx,
            replace_with.into_iter().map(|v| Change::Insert(v)),
        )
        self.apply_changes(last_idx, replace_with.into_iter().map(Change::Insert))
    }

    fn apply_change(&mut self, reference: Option<LogIndex>, change: Change<T>) -> LogIndex {


@@ 117,7 114,6 @@ impl<'a, A: Author, T> Session<'a, A, T> {
    {
        self.chronofold
            .apply_local_changes(self.author, reference, changes)
            .expect("application of own change should never fail")
    }

    /// Returns an iterator over ops in log order, that where created in this

M src/version.rs => src/version.rs +1 -1
@@ 24,7 24,7 @@ impl<A: Author> Version<A> {
    }

    /// Returns an iterator over the timestamps in this version.
    pub fn iter<'a>(&'a self) -> impl Iterator<Item = Timestamp<A>> + 'a {
    pub fn iter(&self) -> impl Iterator<Item = Timestamp<A>> + '_ {
        self.log_indices.iter().map(|(a, i)| Timestamp(*i, *a))
    }


M tests/serialization.rs => tests/serialization.rs +4 -6
@@ 30,11 30,9 @@ fn assert_json_max_len(cfold: &Chronofold<usize, char>, max_len: usize) {
    let json = serde_json::to_string(&cfold).unwrap();
    assert!(
        json.len() <= max_len,
        format!(
            "length of {} is not <= {} (it is {})",
            json,
            max_len,
            json.len()
        )
        "length of {} is not <= {} (it is {})",
        json,
        max_len,
        json.len()
    );
}