pub struct MergeCell<T> { /* private fields */ }
Expand description
A memory location that allows repeated merging.
This type acts like an “accumulator” for merging. It allows merging many values and defering merge errors for later.
MergeCell
deliberately does not implement Merge
. It is not intended
to be merged with other values, rather it expects to have values merged
into it.
§Example
let mut cell = MergeCell::empty();
cell.merge(vec![1, 2]);
cell.merge(vec![]);
cell.merge(vec![0, 4, 8]);
let merged = cell.try_finish().unwrap().unwrap();
assert_eq!(merged, &[1, 2, 0, 4, 8]);
Implementations§
Source§impl<T> MergeCell<T>
impl<T> MergeCell<T>
Sourcepub fn has_errored(&self) -> bool
pub fn has_errored(&self) -> bool
Check whether a previous merge()
operation has failed.
Sourcepub fn finish(self) -> Result<T, Error>
pub fn finish(self) -> Result<T, Error>
Destruct the MergeCell
and get back the final merged value.
Returns the result of all of the merge()
operations on the cell.
§Panics
If the MergeCell
is empty. For the non-panicking version of this
method, see: try_finish()
.
§Example
let mut cell = MergeCell::empty();
cell.merge(vec![1, 2]);
cell.merge(vec![]);
cell.merge(vec![0, 4, 8]);
let merged = cell.finish().unwrap();
assert_eq!(merged, &[1, 2, 0, 4, 8]);
Sourcepub fn try_finish(self) -> Option<Result<T, Error>>
pub fn try_finish(self) -> Option<Result<T, Error>>
Destruct the MergeCell
and get back the final merged value.
This is the non-panicking version of finish()
.
Returns None
if the cell is empty. Otherwise, it is functionally the
same as finish()
.
§Example
let mut cell = MergeCell::empty();
cell.merge(vec![1, 2]);
cell.merge(vec![]);
cell.merge(vec![0, 4, 8]);
let merged = cell.try_finish().unwrap().unwrap();
assert_eq!(merged, &[1, 2, 0, 4, 8]);