Description
I would like to reuse code saved in one playground in another, different playground without having to copy-paste the contents of the original, or having to publish it. This could be useful in several scenarios:
- 📚 Publishing some light library and reusing it in multiple pastes. If there are many copies of a paste with small differences (which I suspect is a common pattern), this could reduce total paste size and improve compile times for the playground runners by caching the dependencies' object files.
- 🐛 If someone is using a paste to demonstrate an issue with their code, reusing it as a dependency with some small tweak would naturally highlight the changes made and may aid their comprehension of the solution.
- 👨🏫 For education purposes, I could see a teacher create a paste that exposes public evaluation functions which must be called to clear some assignment. This would enable the student to focus on the assignment tasks and enables the teacher to know that the evaluation code was not tampered with.
👋 To use it, the playground could reserve a special module name pattern that would dynamically pull in other gists when referencing public items within it. 🚲 Bikeshedding notwithstanding, perhaps something like:
use gist_16aa5441c37dc67c7ce0c8b4b48c194b::{some_pub_fn, other_pub_fn};
// or under some namespace:
use playground::gist_16aa5441c37dc67c7ce0c8b4b48c194b::{some_pub_fn, other_pub_fn};
👩💻 I'm unsure exactly how this could be implemented. Maybe proc macros? A build.rs script that downloads the gist file before compilation? (this could even be reused outside of a playground environment [very carefully]). If using these features introduces undesirable attack surface, parsing the paste for use
statements ahead of time could still be workable.
🔐 I don't think this would cause a material change to possible abuse cases. Obviously, gists saved by the playground are never changed so using another gist as a dependency could not cause pastes to break or cause some observable change in behavior. Total compilation+runtime would still be bounded by the playground runner. Dependencies would still have to be trees, and any code that uses this "paste splitting" feature could be automatically rewritten into a single file to review manually if needed.
Thoughts?