Comments (2)
Started hacking on the compiler side just to see where it slots it on and where it'll land in the final data. Progress branch here: https://github.com/tgolsson/rune/tree/ts/traits.
This is the code that I want to get to compile, ~ish, as a proof of concept.
trait MyTrait {
fn echo(self);
fn name(self) {
"Derek"
}
}
struct MyStruct { a }
impl MyTrait for MyStruct {
fn echo(self) { MyTrait::name(self) }
}
pub fn main() {
let m = MyStruct { a: 10 };
m.echo()
}
from rune.
@udoprog I started thinking about this last night from a "native" side, since I want to emulate Deref for my generic structs - I've got something like
#[derive(Any)]
struct DerefProxy<T>
where
T: runestick::Any,
{
inner: AtomicRefMut<'static, T>,
}
And this wrapper (whose sole purpose is to keep the lock alive) should be Deref<Target = T> just like the inner value is. I'm not sure about exact patterns to make it ergonomic and safe -- I guess there'll need to be some form of "cook" once all traits etc have been registered to generate a dispatch table. My current working idea for surface API is that there'll be something like this:
struct TraitApi { /* todo */ }
trait InstallTrait { /* todo */ }
impl<T> InstallTrait for T where T: std::fmt::Debug {
fn api() -> TraitApi { ... }
fn install(m: &mut Module) -> ... {
m.inst_trait("std::fmt::Debug",
Self::api().inst_fn("fmt", |s: &T, f: &mut String| { ... })
}
}
Where each Module::inst_trait
call is one segment of a virtual table. And then e.g STRING_DEBUG would be vm.dispatch("std::fmt::Debug", "fmt", target, args)
or something like that. Haven't thought too much about this from the compiler perspective though, I guess there needs to be some form of resolution in untyped code -- e.g., how'd one differentiate between mutable/non-mutable access, etc, or simply name clashes between unrelated generic names (get, set, update, fetch, run, ...). You know more about the compiler than I do so I'd love to hear your thoughts on that side.
from rune.
Related Issues (20)
- Support patterns in quote! iterators
- Support `derive(Any)` type protocols HOT 1
- Cannot mutate nested field HOT 2
- Using a dedicated enum for the `Try` protocol HOT 2
- "halted for unexpected reason `awaited`" Error HOT 7
- Should `#[rune::function]` be associated if function returns `Self` HOT 1
- Add default `T=()` to `rune::Result` HOT 1
- Modify a vm function
- Feature request: Traits HOT 3
- Support pattern matching which is open `..` in the middle of an array HOT 1
- Memory sandboxing
- Feature request: Support autocomplete for Ace editor
- Function Pointers HOT 2
- 0.13.0 release build failure HOT 7
- Documentation enhancements HOT 1
- Bad link in rune-modules's README
- Support should_panic for rune tests HOT 3
- Error handling in built-in toml module HOT 3
- Feature request: Support variable swapping HOT 2
- Field not available to get on <struct> HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from rune.