Closed
Description
It should be possible to tell the compiler that at least one of a given set of default methods is required to be implemented, e.g.
#[requires(one_of(foo, bar), one_of(baz, qux))]
trait A {
fn foo(&self) { self.bar() }
fn bar(&self) { self.foo() }
fn baz(&self) { self.qux() }
fn qux(&self) { self.baz() }
}
impl A for int { // ok
fn foo(&self) {}
fn bar(&self) {}
fn baz(&self) {}
}
impl A for uint { // "requires at least one of foo or bar"
fn baz(&self) {}
}
impl A for float { // "requires at least one of baz or qux"
fn foo(&self) {}
}
This allows e.g. Eq
to write eq
and ne
in terms of each other, without allowing the infinitely recursive impl Eq for Foo {}
.
It could even allow saying "either foo
or both bar
and baz
", e.g. #[requires(one_of(foo, all_of(bar, baz)))]
, and would hopefully warn if a non-default method was listed.