frontier: tighter integration with rust traits #469
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The
frontier
module implements a common Rust pattern where there isone type representing a mutable version of something and a separate type
representing its immutable counterpart. Examples in std are
String
andstr
,PathBuf
andPath
,OsString
andOsStr
, and other.In all the examples above the mutable version holds onto a heap
allocated buffer and the immutable version is just a
#[repr(transparent)]
wrapper over an raw unsized slice of the datatype.
This patch changes
AntichainRef<T>
to simply be a transparent wrapperover
[T]
. This change enablesDeref
implementations targeting theimmutable antichain from both
MutableAntichain<T>
andAntichain<T>
.This has a bunch of ergonomic improvements for users (due to auto-deref)
and also allows having a single implementation of all methods that only
need immutable access to the antichain.
Specifically, the following methods have been deduplicated and are now
implemented in only once place:
AntichainRef::less_than
AntichainRef::less_equal
AntichainRef::dominates
AntichainRef::elements
<AntichainRef as PartialEq>::eq
<AntichainRef as PartialOrd>::partial_cmp
<AntichainRef as Hash>::hash
Finally, this change also enables replacing the inherent
Antichain::borrow
andAntichain::to_owned
methods by implementingthe
std::borrow::Borrow
andstd::borrow::ToOwned
traitsrespectively.
Signed-off-by: Petros Angelatos [email protected]