Skip to content

frontier: tighter integration with rust traits #469

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

petrosagg
Copy link
Contributor

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 [email protected]

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 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant