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]>>) -> Merge<T>
pub fn from_vec(values: impl Into<SmallVec<[T; 1]>>) -> Merge<T>
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>,
) -> Merge<T>
pub fn from_removes_adds( removes: impl IntoIterator<Item = T>, adds: impl IntoIterator<Item = T>, ) -> Merge<T>
Creates a new merge object from the given removes and adds.
Sourcepub fn from_diffs(
first_side: T,
diffs: impl IntoIterator<Item = Diff<T>>,
) -> Merge<T>
pub fn from_diffs( first_side: T, diffs: impl IntoIterator<Item = Diff<T>>, ) -> Merge<T>
Creates a Merge from a first side and a series of diffs to apply to
that side.
Sourcepub fn repeated(value: T, num_sides: usize) -> Merge<T>where
T: Clone,
pub fn repeated(value: T, num_sides: usize) -> Merge<T>where
T: Clone,
Creates a Merge by repeating a single value.
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
pub fn removes(&self) -> impl ExactSizeIterator
The removed values, also called negative terms.
Sourcepub fn adds(&self) -> impl ExactSizeIterator
pub fn adds(&self) -> impl ExactSizeIterator
The added values, also called positive terms.
Sourcepub fn into_removes_adds(
self,
) -> (impl ExactSizeIterator, impl ExactSizeIterator)
pub fn into_removes_adds( self, ) -> (impl ExactSizeIterator, impl ExactSizeIterator)
Return the removed values and added values and take the ownership.
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) -> Merge<T>
pub fn simplify(&self) -> Merge<T>
Simplify the merge by joining diffs like A->B and B->C into A->C. Also drops trivial diffs like A->A.
Sourcepub fn simplify_by<'a, U>(&'a self, f: impl FnMut(&'a T) -> U) -> Merge<T>
pub fn simplify_by<'a, U>(&'a self, f: impl FnMut(&'a T) -> U) -> Merge<T>
Simplify the merge, using a function to choose which values to compare.
Sourcepub fn update_from_simplified(self, simplified: Merge<T>) -> Merge<T>where
T: PartialEq,
pub fn update_from_simplified(self, simplified: Merge<T>) -> Merge<T>where
T: PartialEq,
Updates the merge based on the given simplified merge.
Sourcepub fn resolve_trivial(&self, same_change: SameChange) -> Option<&T>
pub fn resolve_trivial(&self, same_change: SameChange) -> 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 as_slice(&self) -> &[T]
pub fn as_slice(&self) -> &[T]
Returns a slice containing the terms. The items will alternate between positive and negative terms, starting with positive (since there’s one more of those).
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.
Sourcepub fn into_map<U>(self, f: impl FnMut(T) -> U) -> Merge<U>
pub fn into_map<U>(self, f: impl FnMut(T) -> U) -> Merge<U>
Creates a new merge by applying f to each remove and add, consuming
self.
Sourcepub fn try_map<'a, U, E>(
&'a self,
f: impl FnMut(&'a T) -> Result<U, E>,
) -> Result<Merge<U>, E>
pub fn try_map<'a, U, E>( &'a self, f: impl FnMut(&'a T) -> Result<U, E>, ) -> Result<Merge<U>, E>
Creates a new merge by applying f to each remove and add, returning
Err if f returns Err for any of them.
Source§impl<T> Merge<Option<T>>
impl<T> Merge<Option<T>>
Sourcepub fn normal(value: T) -> Merge<Option<T>>
pub fn normal(value: T) -> Merge<Option<T>>
Creates a resolved merge with a value of Some(value).
Sourcepub fn is_present(&self) -> bool
pub fn is_present(&self) -> bool
The opposite of is_absent().
Sourcepub fn as_normal(&self) -> Option<&T>
pub fn as_normal(&self) -> Option<&T>
Returns the value if this is present and non-conflicting.
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.
Trait Implementations§
Source§impl<T> ContentHash for Merge<T>where
T: ContentHash,
impl<T> ContentHash for Merge<T>where
T: ContentHash,
impl<T> Eq for Merge<T>where
T: Eq,
Source§impl<T> IntoIterator for Merge<T>
impl<T> IntoIterator for Merge<T>
Source§impl<'a, T> IntoIterator for &'a Merge<T>
impl<'a, T> IntoIterator for &'a Merge<T>
Source§impl<'a, T> IntoIterator for &'a mut Merge<T>
impl<'a, T> IntoIterator for &'a mut Merge<T>
Source§impl<T> MergedTreeValueExt for Merge<Option<T>>
impl<T> MergedTreeValueExt for Merge<Option<T>>
Source§fn is_tree(&self) -> bool
fn is_tree(&self) -> bool
Source§fn is_file_like(&self) -> bool
fn is_file_like(&self) -> bool
Source§fn to_file_merge(&self) -> Option<Merge<Option<FileId>>>
fn to_file_merge(&self) -> Option<Merge<Option<FileId>>>
FileIds. The executable bits and copy IDs will be ignored. Use
Merge::with_new_file_ids() to produce a new merge with the original
executable bits preserved.Source§fn to_executable_merge(&self) -> Option<Merge<Option<bool>>>
fn to_executable_merge(&self) -> Option<Merge<Option<bool>>>
Source§fn to_copy_id_merge(&self) -> Option<Merge<Option<CopyId>>>
fn to_copy_id_merge(&self) -> Option<Merge<Option<CopyId>>>
Source§fn with_new_file_ids(
&self,
file_ids: &Merge<Option<FileId>>,
) -> Merge<Option<TreeValue>>
fn with_new_file_ids( &self, file_ids: &Merge<Option<FileId>>, ) -> Merge<Option<TreeValue>>
self will be preserved. Read moreSource§fn describe(&self, labels: &ConflictLabels) -> String
fn describe(&self, labels: &ConflictLabels) -> String
Source§impl<T> Serialize for Merge<T>where
T: Serialize,
impl<T> Serialize for Merge<T>where
T: Serialize,
Source§fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
impl<T> StructuralPartialEq for Merge<T>where
T: PartialEq,
Source§impl<T> ToTreeMergeExt for Merge<Option<T>>
impl<T> ToTreeMergeExt for Merge<Option<T>>
Source§async fn to_tree_merge(
&self,
store: &Arc<Store>,
dir: &RepoPath,
) -> BackendResult<Option<Merge<Tree>>>
async fn to_tree_merge( &self, store: &Arc<Store>, dir: &RepoPath, ) -> BackendResult<Option<Merge<Tree>>>
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.Source§impl TreeMergeExt for Merge<Tree>
impl TreeMergeExt for Merge<Tree>
Source§fn value(&self, basename: &RepoPathComponent) -> MergedTreeVal<'_>
fn value(&self, basename: &RepoPathComponent) -> MergedTreeVal<'_>
Resolved even if
self is conflicted, which happens if the value at the path can be
trivially merged. Does not recurse, so if basename refers to a Tree,
then a TreeValue::Tree will be returned.Source§async fn sub_tree(
&self,
name: &RepoPathComponent,
) -> BackendResult<Option<Self>>
async fn sub_tree( &self, name: &RepoPathComponent, ) -> BackendResult<Option<Self>>
Merge<Tree> in a subdirectory of the current tree. If the
path doesn’t correspond to a tree in any of the inputs to the merge,
then that entry will be replaced by an empty tree in the result.Source§async fn sub_tree_recursive(
&self,
path: &RepoPath,
) -> BackendResult<Option<Self>>
async fn sub_tree_recursive( &self, path: &RepoPath, ) -> BackendResult<Option<Self>>
Auto Trait Implementations§
impl<T> Freeze for Merge<T>
impl<T> RefUnwindSafe for Merge<T>
impl<T> Send for Merge<T>
impl<T> Sync for Merge<T>
impl<T> Unpin for Merge<T>
impl<T> UnsafeUnpin for Merge<T>
impl<T> UnwindSafe for Merge<T>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more