-
Notifications
You must be signed in to change notification settings - Fork 13k
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
Traits can no longer be mutually dependent #23118
Comments
On Fri, Mar 06, 2015 at 06:10:52AM -0800, Andrew Paseltiner wrote:
Why not merge the two traits, if implementing one always implies |
For this specific example, I'd like to allow multiple implementations of pub trait Lookup<Q: ?Sized> {
type Value;
fn get(&self, key: &Q) -> Option<&Self::Value>;
} and to enforce, at the trait level, that |
Supertraits are explicitly required to be acyclic. This is intentional (@apasel422's specific example can be broken by moving the |
@arielb1 Could you explain your suggested refactoring a bit more? On Tuesday, July 7, 2015, arielb1 notifications@github.com wrote:
|
For anyone who comes across this later, the pattern ends up being something like: pub trait Container {
type Key;
type Value;
}
pub trait MapLookup<Q: ?Sized>: Container {
fn get(&self, key: &Q) -> Option<&Self::Value>;
}
pub trait Map: MapLookup<<Self as Container>::Key> {
fn insert(&mut self, key: Self::Key, value: Self::Value) -> Option<Self::Value>;
} |
Before #23026, it was possible to use where clauses to have traits that must be implemented together, like:
The new version (using either the newly supported supertrait syntax or where clauses) now causes a cycle error:
This is expected, based on @nikomatsakis's comment in the PR:
However, this seems like a useful pattern.
The text was updated successfully, but these errors were encountered: