Ideas for exposing type info


Hi I would like to get some design feedback.

In my source I have lots of types defined that are in the own files in a sub directory of the project.



I wish to introspect these types and manipulate them from a very basic web front end defined in
So I need to somehow get the types to describe themselves (name, types and constructor) to Javascript.

Does anyone have any suggestions for reading material or could suggest crates for this sort of thing ?


What do you want to achieve by “describing themselves”?

The solution is likely to be different depending on the exact need.

For serialization, there’s Serde.

For using the types dynamically you could use Trait Objects or the Any type.

You could also use macros to define the types and some static data structure about them.


The frontend will be something like

Where a user can organise how the Rust structs are connected to one another.
They are basically arranged in a tree like structure.
Some Rust structs can attach to others but not all. It depends on their input / output types . Therefore I will need to pass to Javascript the “capabilities” of each Rust type.

I don’t want to serialise instances

The macro route seems the best so far I think.

Hope that makes sense.


The standard way to do this is to write a custom derive (a compiler plugin) that generates the required rust code. You may be able to use the introspection crate (below) but it’s not very powerful: