Make the change type be generic over any T rather &T (#31)

This makes the interface of this crate more flexible as the utility
methods such as `iter_changes` now also work if a container does not
contain references.
This commit is contained in:
Armin Ronacher 2021-09-11 11:20:51 +02:00 committed by GitHub
parent 0b8e237280
commit a3e10af892
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 75 additions and 37 deletions

View file

@ -159,8 +159,8 @@ impl<'s, T: DiffableStr + ?Sized> InlineChange<'s, T> {
}
}
impl<'s, T: DiffableStr + ?Sized> From<Change<'s, T>> for InlineChange<'s, T> {
fn from(change: Change<'s, T>) -> InlineChange<'s, T> {
impl<'s, T: DiffableStr + ?Sized> From<Change<&'s T>> for InlineChange<'s, T> {
fn from(change: Change<&'s T>) -> InlineChange<'s, T> {
InlineChange {
tag: change.tag(),
old_index: change.old_index(),

View file

@ -495,7 +495,7 @@ impl<'old, 'new, 'bufs, T: DiffableStr + ?Sized + 'old + 'new> TextDiff<'old, 'n
pub fn iter_changes<'x, 'slf>(
&'slf self,
op: &DiffOp,
) -> ChangesIter<'slf, 'x, [&'x T], [&'x T], T>
) -> ChangesIter<'slf, [&'x T], [&'x T], &'x T>
where
'x: 'slf,
'old: 'x,
@ -728,7 +728,7 @@ fn test_get_close_matches() {
fn test_lifetimes_on_iter() {
use crate::Change;
fn diff_lines<'x, T>(old: &'x T, new: &'x T) -> Vec<Change<'x, T::Output>>
fn diff_lines<'x, T>(old: &'x T, new: &'x T) -> Vec<Change<&'x T::Output>>
where
T: DiffableStrRef + ?Sized,
{