kurtlawrence / papyrus

(Rust) repl
MIT License
440 stars 14 forks source link

Injection of using statements #57

Closed kurtlawrence closed 4 years ago

kurtlawrence commented 4 years ago

Goal

Add ability have a piece of code that gets injected on each compilation.

Discussion

The specific use case is to solve where an external library is relying on kserd to display data, but the papyrus version will be trying to solve using its version of kserd.

A fix can be applied by prefixing the source file with use libname::kserd as kserd and this acts as a drop in replacement for the usual crate kserd (which can be accessed using ::kserd). It requires library developers to expose kserd using pub extern crate kserd in their lib.rs file.

This would solve most use cases, however could fall over when the returning type is coming from a dependency in the REPL and implements ToKserd. This would cause the opposite problem (although have not tested) where the ::kserd is required for resolving.

A possible solution is to add a piece of code which can transform libname::kserd to ::kserd.

Aspects to Develop