-
Notifications
You must be signed in to change notification settings - Fork 0
Labels
enhancementNew feature or requestNew feature or requestfrontendRequires work with compiler frontendRequires work with compiler frontendhelp wantedExtra attention is neededExtra attention is needed
Description
Instead of current approach, we could see methods on types as a kind of feature extension.
Let's separate them from the type declaration, because:
- it allows to extend external types (for example coloring methods for strings)
- it can group similar behavior
- it allows for parameter-specific extensions (for example
.product()onVec<i32>)
The main issue that many languages, including Rust, suffers from, is that two independent
crates can implement the same methods/traits, resulting in conflicts. Rust prohibits this
by coherence rules, but I have a (maybe?) better idea — let the extensions be named.
A method is accessible if the name is imported by scope. If two, differently named
extensions add method with the same name, disambiguation is requested by the compiler.
I propose the following syntax:
ext <name> for <type> {
<methods>
}
The question is whether to allow generic extensions (eg. ext<T> vec_impl for Vec<T>)
Sub-issues
Metadata
Metadata
Assignees
Labels
enhancementNew feature or requestNew feature or requestfrontendRequires work with compiler frontendRequires work with compiler frontendhelp wantedExtra attention is neededExtra attention is needed