Serializing rust data to literals

Currently, I have a tool where I can easily generate integration tests by capturing a JSON dump of the current state of my system. This has been really useful, but it's been a major pain to keep that data updated as the internal state representation evolves.

A feature that exists in some programming languages (python, javascript, lisp) is that it's possible to take some data and serialize it to a self-evaluating format, i.e. you can serialize your data to a syntactically valid subset of the programming language itself. The advantage of this data-is-code approach is that when the system changes, you can use all of your standard refactoring tools to make changes to it. Notably in the case of Rust this would mean that the type-checker would run on the data to validate it.

Is there any tool which can handle this kind of behavior in Rust? It would definitely only need to handle a small subset of possible data types, even just doing vectors, structs, strings, and numbers would be 95% of the value proposition.

Failing that, are there some other strategies I could think about to reduce the pain of keeping my test data updated?


1 Like

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.