-
Notifications
You must be signed in to change notification settings - Fork 10
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Const JSON does not compile #10
Comments
Ah I overlooked this completely since for my use case I actually had a |
Thanks @code-mart for reporting this and @AravindPrabhs for the details. I've added a little comment in the README linking to this issue so others can be aware. We may need to remove this if it's not achievable. Closing for now; please feel free to re-open. |
Thanks @Wulf , I achieved this in a different way in my project. In order to evaluate macros (including concatenation of static strings, which is a basic feature for string constants), tsync would need to be working with a compiled project, rather than working with the source code, like tsync does now. This is because there is not a good, stable way (that I have found) to evaluate macros before compilation. Additionally, with tsync's approach of using attribute-like macros, #[tsync], I could not find an elegant way to run the tsync code as part of the compiled project, without, for example, adding a function call to main. I ended up creating a separate "constant-definer" crate, where I could include the constants in my rust code, and I would run all my export!() function-like macros to export the constants to typescript. This is basically what it looks like:
There may be a way to integrate this feature into tsync by using tsync as a library, as you have already implemented. Please share any thoughts! |
Great solution @code-mart! Thank you for sharing. That's definitely an elegant way to go about static values. There's one adaptation which may make it easier to integrate with tsync. It would be to have the #[tsync] macro keep track of all statics using something like Definitely a great feature to add! This alongside @AravindPrabhs's cargo expansion would make tsync more powerful than it was initially intended to be 😅 🙌 |
The following example, found in test/const/rust.rs does not compile for me:
I get this error, among others:
From my understanding, the constructor for serde_json::Value is not const, so using json! macro to initialize a const macro is not possible. Is there some way to successfully compile the const JSON?
The text was updated successfully, but these errors were encountered: