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 new(removes: Vec<T>, adds: Vec<T>) -> Self
pub fn new(removes: Vec<T>, adds: Vec<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 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>where
T: Eq + Hash,
pub fn resolve_trivial(&self) -> Option<&T>where T: Eq + Hash,
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) -> impl Iterator<Item = &T>
pub fn iter(&self) -> impl Iterator<Item = &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) -> impl Iterator<Item = &mut T>
pub fn iter_mut(&mut self) -> impl Iterator<Item = &mut 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 non-executable files or absent entries,
returns a merge of the FileId
s`.
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>>where
T: Borrow<TreeValue>,
impl<T> Merge<Option<T>>where T: Borrow<TreeValue>,
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 Merge<Option<TreeValue>>
is a TreeValue::Tree
, this converts it to
a Merge<Tree>
, with empty trees instead of
any None
terms. Otherwise, returns None
.