rscarson / rustyscript

Effortless JS integration for rust
MIT License
98 stars 10 forks source link

WIP Add custom import schemes (no new trait) #146

Closed ac-z closed 5 days ago

ac-z commented 6 days ago

This is a simpler implementation of the custom imports feature I previously proposed. In this iteration, instead of providing structs that implement a trait, the user can provide a HashMap of boxed functions keyed by strings which correspond to URL schemes. While I would have liked for custom import handlers to store data in a struct, I figured making this functionality presentable first is more important. This works with existing examples, but isn't polished yet. Any advice is appreciated.

rscarson commented 6 days ago

I like this approach a lot more But if I can suggest a middle ground,

How do you feel about an ImportProvider trait with a resolve method and an import method that would be in a single option box

It could replace the default deny all, and we could leave the default file/http behavior in place

Easier to use than this with minimal changes to the api, and requires only a small change from what you've already done

I appreciate the work you're putting into this, thank you again

ac-z commented 5 days ago

Closing in favor of a newer branch