Repository navigation
Add a store of Rust classes to PyContext - #857
coolreader18 wants to merge 2 commits into
Conversation
| } | ||
|
|
||
| pub fn _get_class(&self, typeid: &TypeId) -> Option<PyClassRef> { | ||
| self.rust_classes.borrow_mut().get(typeid).cloned() |
There was a problem hiding this comment.
No need to use borrow_mut here, we are not mutating the mapping.
|
@coolreader18 thank's for your work on this. Getting a member from the module itself is not solved well at this point. I have mixed feelings about this change. On the one hand, it solves the issue of getting a rust type from the VM in a better way, rather then getting it via a get module hack. On the other hand, we still require the module if we want to retrieve a variable or function. One other remark, with this route we store all rust classes of all modules on the pycontext, this potentially exposes all classes to all modules. I don't think this is the way to go. I think is better to provide a mechanism such that each function in a module has access to its containing module. Maybe by extending the magic argument types with a Or maybe we can use a closure to fix this? Something like this: In other words, I am not convinced this is the way to go. |
|
What do you think about struct modules then? i.e. a module would be defined as a struct with specifically defined fields as well as a string-keyed dict, stored somewhere as just a |
|
Yeah, I think that is already better. It sort of duplicates the |
|
What you were describing with a |
|
Okay, in that case I prefer to keep the current system with the strings. This also works, although it is a bit weird. Lets wait for the opinions of other reviewers. |
|
I'm currently working on a struct modules implementation, which would eliminate the need for this. Should we close this for now? |
|
Maybe leave this open to allow the others to have a look at this idea. What is the idea with the struct modules? |
|
A |
|
Or maybe |
I extracted this from #848, and I plan to add an
extendscapability to#[pyclass], but that also depends on this feature and I didn't want to put all of that in #848. Also, I feel like this is a good compromise for how to store classes likejson.JSONDecodeError- builtin types are still stored as struct fields, but you also have the capability to map an arbitrary Rust type to a class. It's certainly more performant than looking it up as a string key of a module dict!