Apply more lints

This commit is contained in:
Andras Schmelczer 2024-12-18 22:14:09 +00:00
commit 1e1dd7b877
No known key found for this signature in database
GPG key ID: FC8F2C3D3D1A718C
24 changed files with 61 additions and 63 deletions

View file

@ -1,4 +1,4 @@
use std::iter;
use core::iter;
#[cfg(feature = "serde")]
use serde::{Deserialize, Serialize};
@ -9,17 +9,17 @@ use crate::{
operation_transformation::merge_context::MergeContext,
tokenizer::{word_tokenizer::word_tokenizer, Tokenizer},
utils::{
merge_iters::MergeSorted, ordered_operation::OrderedOperation, side::Side,
merge_iters::MergeSorted as _, ordered_operation::OrderedOperation, side::Side,
string_builder::StringBuilder,
},
};
/// A sequence of operations that can be applied to a text document.
/// EditedText supports merging two sequences of operations using the
/// `EditedText` supports merging two sequences of operations using the
/// principle of Operational Transformation.
///
/// It's mainly created through the from_strings method, then merged with
/// another EditedText derived from the same original text and then applied to
/// It's mainly created through the `from_strings` method, then merged with
/// another `EditedText` derived from the same original text and then applied to
/// the original text to get the reconciled text of concurrent edits.
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[derive(Debug, Clone, PartialEq, Default)]
@ -32,13 +32,13 @@ where
}
impl<'a> EditedText<'a, String> {
/// Create an EditedText from the given original (old) and updated (new)
/// strings. The returned EditedText represents the changes from the
/// Create an `EditedText` from the given original (old) and updated (new)
/// strings. The returned `EditedText` represents the changes from the
/// original to the updated text. When the return value is applied to
/// the original text, it will result in the updated text. The default
/// word tokenizer is used to tokenize the text which splits the text on
/// whitespaces.
pub fn from_strings(original: &'a str, updated: &str) -> Self {
#[must_use] pub fn from_strings(original: &'a str, updated: &str) -> Self {
Self::from_strings_with_tokenizer(original, updated, &word_tokenizer)
}
}
@ -47,8 +47,8 @@ impl<'a, T> EditedText<'a, T>
where
T: PartialEq + Clone,
{
/// Create an EditedText from the given original (old) and updated (new)
/// strings. The returned EditedText represents the changes from the
/// Create an `EditedText` from the given original (old) and updated (new)
/// strings. The returned `EditedText` represents the changes from the
/// original to the updated text. When the return value is applied to
/// the original text, it will result in the updated text. The tokenizer
/// function is used to tokenize the text.
@ -167,7 +167,7 @@ where
result
}
/// Create a new EditedText with the given operations.
/// Create a new `EditedText` with the given operations.
/// The operations must be in the order in which they are meant to be
/// applied. The operations must not overlap.
fn new(text: &'a str, operations: Vec<OrderedOperation<T>>) -> Self {
@ -186,7 +186,7 @@ where
Self { text, operations }
}
pub fn merge(self, other: Self) -> Self {
#[must_use] pub fn merge(self, other: Self) -> Self {
debug_assert_eq!(
self.text, other.text,
"EditedTexts must be derived from the same text to be mergable"
@ -207,7 +207,7 @@ where
operation.order,
// Operations on left and right must come in the same order so that
// inserts can be merged with other inserts and deletes with deletes.
matches!(operation.operation, Operation::Delete { .. }) as usize,
usize::from(matches!(operation.operation, Operation::Delete { .. })),
)
},
)
@ -233,9 +233,9 @@ where
///
/// # Errors
///
/// Returns an SyncLibError::OperationError if the operations cannot be
/// Returns an `SyncLibError::OperationError` if the operations cannot be
/// applied to the text.
pub fn apply(&self) -> String {
#[must_use] pub fn apply(&self) -> String {
let mut builder: StringBuilder<'_> = StringBuilder::new(self.text);
for OrderedOperation { operation, .. } in &self.operations {