pub struct Merge<T> { /* private fields */ }
Expand description
A generic representation of merged values.
There is exactly one more adds()
than removes()
. When interpreted as a
series of diffs, the merge’s (i+1)-st add is matched with the i-th
remove. The zeroth add is considered a diff from the non-existent state.
Implementations§
source§impl<T> Merge<T>
impl<T> Merge<T>
sourcepub fn from_vec(values: impl Into<SmallVec<[T; 1]>>) -> Self
pub fn from_vec(values: impl Into<SmallVec<[T; 1]>>) -> Self
Creates a Merge
from the given values, in which positive and negative
terms alternate.
sourcepub fn from_removes_adds(
removes: impl IntoIterator<Item = T>,
adds: impl IntoIterator<Item = T>
) -> Self
pub fn from_removes_adds( removes: impl IntoIterator<Item = T>, adds: impl IntoIterator<Item = T> ) -> Self
Creates a new merge object from the given removes and adds.
sourcepub fn from_legacy_form(
removes: impl IntoIterator<Item = T>,
adds: impl IntoIterator<Item = T>
) -> Merge<Option<T>>
pub fn from_legacy_form( removes: impl IntoIterator<Item = T>, adds: impl IntoIterator<Item = T> ) -> Merge<Option<T>>
Create a Merge
from a removes
and adds
, padding with None
to
make sure that there is exactly one more adds
than removes
.
sourcepub fn removes(&self) -> impl ExactSizeIterator<Item = &T>
pub fn removes(&self) -> impl ExactSizeIterator<Item = &T>
The removed values, also called negative terms.
sourcepub fn adds(&self) -> impl ExactSizeIterator<Item = &T>
pub fn adds(&self) -> impl ExactSizeIterator<Item = &T>
The added values, also called positive terms.
sourcepub fn get_remove(&self, index: usize) -> Option<&T>
pub fn get_remove(&self, index: usize) -> Option<&T>
Returns the index
-th removed value, which is considered belonging to
the index
-th diff pair.
sourcepub fn get_add(&self, index: usize) -> Option<&T>
pub fn get_add(&self, index: usize) -> Option<&T>
Returns the index
-th added value, which is considered belonging to the
index-1
-th diff pair. The zeroth add is a diff from the non-existent
state.
sourcepub fn swap_remove(&mut self, remove_index: usize, add_index: usize) -> (T, T)
pub fn swap_remove(&mut self, remove_index: usize, add_index: usize) -> (T, T)
Removes the specified “removed”/“added” values. The removed slots are replaced by the last “removed”/“added” values.
sourcepub fn is_resolved(&self) -> bool
pub fn is_resolved(&self) -> bool
Whether this merge is resolved. Does not resolve trivial merges.
sourcepub fn as_resolved(&self) -> Option<&T>
pub fn as_resolved(&self) -> Option<&T>
Returns the resolved value, if this merge is resolved. Does not resolve trivial merges.
sourcepub fn into_resolved(self) -> Result<T, Merge<T>>
pub fn into_resolved(self) -> Result<T, Merge<T>>
Returns the resolved value, if this merge is resolved. Otherwise returns
the merge itself as an Err
. Does not resolve trivial merges.
sourcepub fn simplify(self) -> Selfwhere
T: PartialEq,
pub fn simplify(self) -> Selfwhere
T: PartialEq,
Simplify the merge by joining diffs like A->B and B->C into A->C. Also drops trivial diffs like A->A.
sourcepub fn resolve_trivial(&self) -> Option<&T>
pub fn resolve_trivial(&self) -> Option<&T>
If this merge can be trivially resolved, returns the value it resolves to.
sourcepub fn pad_to(&mut self, num_sides: usize, value: &T)where
T: Clone,
pub fn pad_to(&mut self, num_sides: usize, value: &T)where
T: Clone,
Pads this merge with to the specified number of sides with the specified value. No-op if the requested size is not larger than the current size.
sourcepub fn iter(&self) -> Iter<'_, T>
pub fn iter(&self) -> Iter<'_, T>
Returns an iterator over references to the terms. The items will alternate between positive and negative terms, starting with positive (since there’s one more of those).
sourcepub fn iter_mut(&mut self) -> IterMut<'_, T>
pub fn iter_mut(&mut self) -> IterMut<'_, T>
A version of Merge::iter()
that iterates over mutable references.
sourcepub fn map<'a, U>(&'a self, f: impl FnMut(&'a T) -> U) -> Merge<U>
pub fn map<'a, U>(&'a self, f: impl FnMut(&'a T) -> U) -> Merge<U>
Creates a new merge by applying f
to each remove and add.
source§impl<T> Merge<Option<T>>
impl<T> Merge<Option<T>>
sourcepub fn is_present(&self) -> bool
pub fn is_present(&self) -> bool
The opposite of is_absent()
.
sourcepub fn into_legacy_form(self) -> (Vec<T>, Vec<T>)
pub fn into_legacy_form(self) -> (Vec<T>, Vec<T>)
Creates lists of removes
and adds
from a Merge
by dropping
None
values. Note that the conversion is lossy: the order of None
values is not preserved when converting back to a Merge
.
source§impl Merge<Option<TreeValue>>
impl Merge<Option<TreeValue>>
sourcepub fn from_backend_conflict(conflict: Conflict) -> Self
pub fn from_backend_conflict(conflict: Conflict) -> Self
Create a Merge
from a backend::Conflict
, padding with None
to
make sure that there is exactly one more adds()
than removes()
.
sourcepub fn into_backend_conflict(self) -> Conflict
pub fn into_backend_conflict(self) -> Conflict
Creates a backend::Conflict
from a Merge
by dropping None
values. Note that the conversion is lossy: the order of None
values is
not preserved when converting back to a Merge
.
sourcepub fn is_tree(&self) -> bool
pub fn is_tree(&self) -> bool
Whether this merge should be recursed into when doing directory walks.
sourcepub fn to_file_merge(&self) -> Option<Merge<Option<FileId>>>
pub fn to_file_merge(&self) -> Option<Merge<Option<FileId>>>
If this merge contains only files or absent entries, returns a merge of
the FileId
s. The executable bits will be ignored. Use
Merge::with_new_file_ids()` to produce a new merge with the original
executable bits preserved.
sourcepub fn with_new_file_ids(&self, file_ids: &Merge<Option<FileId>>) -> Self
pub fn with_new_file_ids(&self, file_ids: &Merge<Option<FileId>>) -> Self
Creates a new merge with the file ids from the given merge. In other
words, only the executable bits from self
will be preserved.
source§impl<T> Merge<Option<T>>
impl<T> Merge<Option<T>>
sourcepub fn to_tree_merge(
&self,
store: &Arc<Store>,
dir: &RepoPath
) -> Result<Option<Merge<Tree>>, BackendError>
pub fn to_tree_merge( &self, store: &Arc<Store>, dir: &RepoPath ) -> Result<Option<Merge<Tree>>, BackendError>
If every non-None
term of a MergedTreeValue
is a TreeValue::Tree
, this converts it to
a Merge<Tree>
, with empty trees instead of
any None
terms. Otherwise, returns None
.