Lint & format

This commit is contained in:
Andras Schmelczer 2025-04-06 11:39:40 +01:00
commit 48f301d8ab
No known key found for this signature in database
GPG key ID: FC8F2C3D3D1A718C
2 changed files with 54 additions and 57 deletions

View file

@ -35,7 +35,7 @@ use crate::{
/// Diff `old`, between indices `old_range` and `new` between indices
/// `new_range`.
///
/// The returned RawOperations all have a token count of 1.
/// The returned `RawOperations` all have a token count of 1.
pub fn diff<T>(old: &[Token<T>], new: &[Token<T>]) -> Vec<RawOperation<T>>
where
T: PartialEq + Clone + std::fmt::Debug,
@ -245,7 +245,7 @@ fn conquer<T>(
old[old_range.start..old_range.start + common_prefix_len]
.iter()
.map(|token| RawOperation::Equal(vec![token.clone()])),
)
);
}
old_range.start += common_prefix_len;
new_range.start += common_prefix_len;
@ -266,13 +266,13 @@ fn conquer<T>(
old[old_range.start..old_range.start + old_range.len()]
.iter()
.map(|token| RawOperation::Delete(vec![token.clone()])),
)
);
} else if old_range.is_empty() {
result.extend(
new[new_range.start..new_range.start + new_range.len()]
.iter()
.map(|token| RawOperation::Insert(vec![token.clone()])),
)
);
} else if let Some((x_start, y_start)) =
find_middle_snake(old, old_range.clone(), new, new_range.clone(), vf, vb)
{

View file

@ -30,18 +30,18 @@ where
pub fn is_left_joinable(&self) -> bool {
let first_token = self.tokens().first();
first_token.map_or(true, |t| t.get_is_left_joinable())
first_token.is_none_or(super::super::tokenizer::token::Token::get_is_left_joinable)
}
pub fn is_right_joinable(&self) -> bool {
let last_token = self.tokens().last();
last_token.map_or(true, |t| t.get_is_right_joinable())
last_token.is_none_or(super::super::tokenizer::token::Token::get_is_right_joinable)
}
/// Extends the operation with another operation when it returns Some
/// operation. Only operations of the same type as self can be used to
/// extend self. If the operations are of different types, returns None.
pub fn extend(self, other: RawOperation<T>) -> Option<RawOperation<T>> {
/// Extends the operation with another operation. Only operations of the
/// same type as self can be used to extend self, otherwise the function
/// will panic.
pub fn extend(self, other: RawOperation<T>) -> RawOperation<T> {
debug_assert!(
std::mem::discriminant(&self) == std::mem::discriminant(&other),
"Cannot extend operations of different types. This should have been handled before \
@ -49,15 +49,15 @@ where
);
match (self, other) {
(RawOperation::Insert(tokens1), RawOperation::Insert(tokens2)) => Some(
RawOperation::Insert(tokens1.into_iter().chain(tokens2).collect()),
),
(RawOperation::Delete(tokens1), RawOperation::Delete(tokens2)) => Some(
RawOperation::Delete(tokens1.into_iter().chain(tokens2).collect()),
),
(RawOperation::Equal(tokens1), RawOperation::Equal(tokens2)) => Some(
RawOperation::Equal(tokens1.into_iter().chain(tokens2).collect()),
),
(RawOperation::Insert(tokens1), RawOperation::Insert(tokens2)) => {
RawOperation::Insert(tokens1.into_iter().chain(tokens2).collect())
}
(RawOperation::Delete(tokens1), RawOperation::Delete(tokens2)) => {
RawOperation::Delete(tokens1.into_iter().chain(tokens2).collect())
}
(RawOperation::Equal(tokens1), RawOperation::Equal(tokens2)) => {
RawOperation::Equal(tokens1.into_iter().chain(tokens2).collect())
}
_ => unreachable!("Only operations of the same type can be extended"),
}
}