frontier: tighter integration with rust traits#469
Open
petrosagg wants to merge 1 commit intoTimelyDataflow:masterfrom
Open
frontier: tighter integration with rust traits#469petrosagg wants to merge 1 commit intoTimelyDataflow:masterfrom
petrosagg wants to merge 1 commit intoTimelyDataflow:masterfrom
Conversation
The `frontier` module implements a common Rust pattern where there is one type representing a mutable version of something and a separate type representing its immutable counterpart. Examples in std are `String` and `str`, `PathBuf` and `Path`, `OsString` and `OsStr`, 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 data type. This patch changes `AntichainRef<T>` to simply be a transparent wrapper over `[T]`. This change enables `Deref` implementations targeting the immutable antichain from both `MutableAntichain<T>` and `Antichain<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` and `Antichain::to_owned` methods by implementing the `std::borrow::Borrow` and `std::borrow::ToOwned` traits respectively. Signed-off-by: Petros Angelatos <petrosagg@gmail.com>
aa6180f to
04f2c61
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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
frontiermodule 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
Stringandstr,PathBufandPath,OsStringandOsStr, 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 enablesDerefimplementations 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_thanAntichainRef::less_equalAntichainRef::dominatesAntichainRef::elements<AntichainRef as PartialEq>::eq<AntichainRef as PartialOrd>::partial_cmp<AntichainRef as Hash>::hashFinally, this change also enables replacing the inherent
Antichain::borrowandAntichain::to_ownedmethods by implementingthe
std::borrow::Borrowandstd::borrow::ToOwnedtraitsrespectively.
Signed-off-by: Petros Angelatos petrosagg@gmail.com