You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This issue was labelled with: A-attributes, A-diagnostics, A-lint, A-traits, B-RFC, I-wishlist in the Rust repository
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))]traitA{fnfoo(&self){self.bar()}fnbar(&self){self.foo()}fnbaz(&self){self.qux()}fnqux(&self){self.baz()}}implAforint{// okfnfoo(&self){}fnbar(&self){}fnbaz(&self){}}implAforuint{// "requires at least one of foo or bar"fnbaz(&self){}}implAforfloat{// "requires at least one of baz or qux"fnfoo(&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.
The text was updated successfully, but these errors were encountered:
So an idea here that I want get_b to have a default implementation if B = A or require it otherwise. ideally it should work for associated types as well:
Issue by huonw
Saturday Jul 13, 2013 at 08:41 GMT
For earlier discussion, see rust-lang/rust#7771
This issue was labelled with: A-attributes, A-diagnostics, A-lint, A-traits, B-RFC, I-wishlist in the Rust repository
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.
This allows e.g.
Eq
to writeeq
andne
in terms of each other, without allowing the infinitely recursiveimpl Eq for Foo {}
.It could even allow saying "either
foo
or bothbar
andbaz
", e.g.#[requires(one_of(foo, all_of(bar, baz)))]
, and would hopefully warn if a non-default method was listed.The text was updated successfully, but these errors were encountered: