-
Notifications
You must be signed in to change notification settings - Fork 83
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
Feature request: Traits #633
Comments
I've started working on this here https://github.com/Fluffyalien1422/rune |
Also see #23 Some thoughts: Since traits and their associated methods can be defined elsewhere (e.g. other crates where they trait is defined), they can't strictly be syntactic sugar for impl blocks. So how do you propose dealing with method naming conflicts and potential disambiguation? How would method name resolution work? In Rust, the methods of a trait are only visible implicitly if the trait is in scope, but this relies on knowing the types of values which we obviously don't in Rune. In #23 traits are solely used to define protocols. And this could be a nice area for you to explore since we currently can't implement protocols in pure Rune. Thanks! |
idk how the codebase works exactly yet so idk if this will actually work but here's the idea: trait X {
fn no_default_implementation();
fn default_implementation() {
println!("Hello, World!");
}
}
struct Y {};
impl X for Y {
fn no_default_implementation() {
println!("Bye!");
}
} Is the same as struct Y {};
impl Y {
fn no_default_implementation() {
println!("Bye!");
}
fn default_implementation() {
println!("Hello, World!");
}
} So it wouldn't matter if the trait is in scope because the trait only exists to give compiler errors and to fill in default implementations, it will actually just end up being exactly the same as a normal impl block
struct X {}
impl a::b::C for X {}
|
There are already
impl
blocks but no traitsTraits can be syntax sugar for regular
impl
blocksis the same as:
The text was updated successfully, but these errors were encountered: