Rust - Emit attribute support for string templates #2875
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This adds support for full substitution syntax, allowing better bindings to be created to native Rust libs.
I know we sort of agreed not to do this as it modifies the original Rust AST, which is a carbon copy of the real AST from the compiler (and thus runs the risk of diverging). That being said, It seems the only realistic alternative is to introduce a full Rust AST Parser, which seems like a massive undertaking and adds significant bloat to Fable.
At least this way we can move forward.
I have added a few basic tests to prove you can call into some std libs such as f64 and Vec by value or by reference, but there are still quite a few caveats to iron out. I have assumed everything entering a template is passed by value, as I think this is the most sensible default. If you want to pass by reference you can just prefix with & like normal Rust. This might need some refinement around function parameters, which will be implicitly by-ref, and need to be dereferenced with *.
Also added a MutDeref to MutCell. It occurred to me recently that Deref and MutDeref might well be a rather convenient escape hatch to deal with some of the complex unwrapping problems we have struggled with for classes etc down the road. One to revisit perhaps. These do need to be imported to work though, but it may clean up some dereferencing fluff.