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