From d23fad5382fa4024c63cdb74469a6b0c2d1c135d Mon Sep 17 00:00:00 2001 From: Andras Schmelczer Date: Sun, 29 Jun 2025 15:57:04 +0100 Subject: [PATCH] Import Debug instead of full reference --- src/operation_transformation.rs | 3 ++- src/operation_transformation/edited_text.rs | 6 ++++-- src/operation_transformation/operation.rs | 8 ++++---- src/operation_transformation/utils/cook_operations.rs | 4 +++- src/operation_transformation/utils/elongate_operations.rs | 3 ++- src/tokenizer/token.rs | 8 +++++--- src/utils/find_longest_prefix_contained_within.rs | 8 +++++--- src/utils/myers_diff.rs | 7 ++++--- 8 files changed, 29 insertions(+), 18 deletions(-) diff --git a/src/operation_transformation.rs b/src/operation_transformation.rs index 7cd88d9..0ff9405 100644 --- a/src/operation_transformation.rs +++ b/src/operation_transformation.rs @@ -2,6 +2,7 @@ mod cursor; mod edited_text; mod operation; mod utils; +use std::fmt::Debug; pub use cursor::{CursorPosition, TextWithCursors}; pub use edited_text::EditedText; @@ -49,7 +50,7 @@ pub fn reconcile_with_tokenizer<'a, F, T>( tokenizer: &Tokenizer, ) -> TextWithCursors<'static> where - T: PartialEq + Clone + std::fmt::Debug, + T: PartialEq + Clone + Debug, { let left_operations = EditedText::from_strings_with_tokenizer(original, left, tokenizer, Side::Left); diff --git a/src/operation_transformation/edited_text.rs b/src/operation_transformation/edited_text.rs index 34f42b8..30643b1 100644 --- a/src/operation_transformation/edited_text.rs +++ b/src/operation_transformation/edited_text.rs @@ -1,3 +1,5 @@ +use std::fmt::Debug; + #[cfg(feature = "serde")] use serde::{Deserialize, Serialize}; @@ -27,7 +29,7 @@ use crate::{ #[derive(Debug, Clone, PartialEq, Default)] pub struct EditedText<'a, T> where - T: PartialEq + Clone + std::fmt::Debug, + T: PartialEq + Clone + Debug, { text: &'a str, operations: Vec>, @@ -49,7 +51,7 @@ impl<'a> EditedText<'a, String> { impl<'a, T> EditedText<'a, T> where - T: PartialEq + Clone + std::fmt::Debug, + T: PartialEq + Clone + Debug, { /// Create an `EditedText` from the given original (old) and updated (new) /// strings. The returned `EditedText` represents the changes from the diff --git a/src/operation_transformation/operation.rs b/src/operation_transformation/operation.rs index 652eb3e..05aad3f 100644 --- a/src/operation_transformation/operation.rs +++ b/src/operation_transformation/operation.rs @@ -16,7 +16,7 @@ use crate::{ #[derive(Clone, PartialEq)] pub enum Operation where - T: PartialEq + Clone + std::fmt::Debug, + T: PartialEq + Clone + Debug, { Equal { order: usize, @@ -46,7 +46,7 @@ where impl Operation where - T: PartialEq + Clone + std::fmt::Debug, + T: PartialEq + Clone + Debug, { /// Creates an equal operation with the given index. /// This operation is used to indicate that the text at the given index @@ -332,7 +332,7 @@ where impl Display for Operation where - T: PartialEq + Clone + std::fmt::Debug, + T: PartialEq + Clone + Debug, { fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { match self { @@ -400,7 +400,7 @@ where impl Debug for Operation where - T: PartialEq + Clone + std::fmt::Debug, + T: PartialEq + Clone + Debug, { fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { write!(f, "{self}") } } diff --git a/src/operation_transformation/utils/cook_operations.rs b/src/operation_transformation/utils/cook_operations.rs index 8d09f6f..e8ebd40 100644 --- a/src/operation_transformation/utils/cook_operations.rs +++ b/src/operation_transformation/utils/cook_operations.rs @@ -1,3 +1,5 @@ +use std::fmt::Debug; + use crate::{operation_transformation::Operation, raw_operation::RawOperation, utils::side::Side}; /// Turn raw operations into ordered operations while keeping track of the @@ -5,7 +7,7 @@ use crate::{operation_transformation::Operation, raw_operation::RawOperation, ut pub fn cook_operations(raw_operations: I, side: Side) -> impl Iterator> where I: IntoIterator>, - T: PartialEq + Clone + std::fmt::Debug, + T: PartialEq + Clone + Debug, { let mut original_text_index = 0; // this is the start index of the operation on the original text diff --git a/src/operation_transformation/utils/elongate_operations.rs b/src/operation_transformation/utils/elongate_operations.rs index 57d1580..fd388be 100644 --- a/src/operation_transformation/utils/elongate_operations.rs +++ b/src/operation_transformation/utils/elongate_operations.rs @@ -1,4 +1,5 @@ use core::iter; +use std::fmt::Debug; use crate::raw_operation::RawOperation; @@ -8,7 +9,7 @@ use crate::raw_operation::RawOperation; pub fn elongate_operations(raw_operations: I) -> Vec> where I: IntoIterator>, - T: PartialEq + Clone + std::fmt::Debug, + T: PartialEq + Clone + Debug, { // This might look bad, but this makes sense. The inserts and deltes can be // interleaved, such as: IDIDID and we need to turn this into IIIDDD. diff --git a/src/tokenizer/token.rs b/src/tokenizer/token.rs index 0c12770..f2926af 100644 --- a/src/tokenizer/token.rs +++ b/src/tokenizer/token.rs @@ -1,3 +1,5 @@ +use std::fmt::Debug; + #[cfg(feature = "serde")] use serde::{Deserialize, Serialize}; @@ -12,7 +14,7 @@ use serde::{Deserialize, Serialize}; #[derive(Debug, Clone)] pub struct Token where - T: PartialEq + Clone + std::fmt::Debug, + T: PartialEq + Clone + Debug, { /// The normalised form of the token used deriving the diff. normalised: T, @@ -35,7 +37,7 @@ impl From<&str> for Token { impl Token where - T: PartialEq + Clone + std::fmt::Debug, + T: PartialEq + Clone + Debug, { pub fn new( normalised: T, @@ -62,7 +64,7 @@ where impl PartialEq for Token where - T: PartialEq + Clone + std::fmt::Debug, + T: PartialEq + Clone + Debug, { fn eq(&self, other: &Self) -> bool { self.normalised == other.normalised } } diff --git a/src/utils/find_longest_prefix_contained_within.rs b/src/utils/find_longest_prefix_contained_within.rs index a04da4e..bccb06a 100644 --- a/src/utils/find_longest_prefix_contained_within.rs +++ b/src/utils/find_longest_prefix_contained_within.rs @@ -1,7 +1,9 @@ +use std::fmt::Debug; + use crate::Token; -/// Given two lists of tokens, returns `length` where `old` list somewhere -/// within contains the `length` prefix of the `new` list. +/// Given two lists of tokens, returns `length` where the `old` list +/// somewhere within contains the `length` prefix of the `new` list. /// /// ## Example /// @@ -25,7 +27,7 @@ use crate::Token; /// > results in a length of 1 pub fn find_longest_prefix_contained_within(old: &[Token], new: &[Token]) -> usize where - T: PartialEq + Clone + std::fmt::Debug, + T: PartialEq + Clone + Debug, { let max_possible = new.len().min(old.len()); diff --git a/src/utils/myers_diff.rs b/src/utils/myers_diff.rs index b94270c..4215125 100644 --- a/src/utils/myers_diff.rs +++ b/src/utils/myers_diff.rs @@ -20,6 +20,7 @@ //! For potential improvements here see [similar#15](https://github.com/mitsuhiko/similar/issues/15). use std::{ + fmt::Debug, ops::{Index, IndexMut, Range}, vec, }; @@ -38,7 +39,7 @@ use crate::{ /// The returned `RawOperations` each wrap a single token. pub fn myers_diff(old: &[Token], new: &[Token]) -> Vec> where - T: PartialEq + Clone + std::fmt::Debug, + T: PartialEq + Clone + Debug, { let max_d = (old.len() + new.len()).div_ceil(2) + 1; let mut vb = V::new(max_d); @@ -130,7 +131,7 @@ fn find_middle_snake( vb: &mut V, ) -> Option<(usize, usize)> where - T: PartialEq + Clone + std::fmt::Debug, + T: PartialEq + Clone + Debug, { let n = old_range.len(); let m = new_range.len(); @@ -236,7 +237,7 @@ fn conquer( vb: &mut V, result: &mut Vec>, ) where - T: PartialEq + Clone + std::fmt::Debug, + T: PartialEq + Clone + Debug, { // Check for common prefix let common_prefix_len = common_prefix_len(old, old_range.clone(), new, new_range.clone());