8 stable releases

1.6.0 May 12, 2023
1.5.1 May 4, 2023
1.5.0 Apr 13, 2023
1.4.0 Mar 30, 2023
1.0.0 Nov 22, 2022

#284 in Procedural macros

Download history 176/week @ 2023-02-06 1257/week @ 2023-02-13 2491/week @ 2023-02-20 2411/week @ 2023-02-27 3069/week @ 2023-03-06 2408/week @ 2023-03-13 3280/week @ 2023-03-20 2882/week @ 2023-03-27 2212/week @ 2023-04-03 3901/week @ 2023-04-10 2568/week @ 2023-04-17 2460/week @ 2023-04-24 1672/week @ 2023-05-01 1934/week @ 2023-05-08 1082/week @ 2023-05-15 1426/week @ 2023-05-22

6,140 downloads per month
Used in typeshare-cli



Rust 4K SLoC // 0.0% comments Swift 1.5K SLoC // 0.0% comments Go 1.5K SLoC // 0.0% comments Kotlin 716 SLoC // 0.1% comments Scala 715 SLoC // 0.1% comments TypeScript 299 SLoC // 0.1% comments


The core library behind typeshare, containing type definitions, parsing, and code generation.


Formatting code is hard. Like, really, really hard. Typeshare happens to be a program that needs to generate beautifully formatted code in multiple languages.

In the interests of avoiding the complexities of formatting code perfectly, typeshare takes the approach of generating "best-effort" output that it then runs through the appropriate formatting tool for each language. This makes typeshare's output exactly what language devs would expect, every time, with minimal effort on our part.

Generating well-formatted output therefore requires you to have the appropriate formatting tools for each language installed and available when running typeshare. If you don't have them, typeshare's default (and less pretty) output will be used.


typeshare's test suite is built on the concept of snapshot testing, a data-driven testing methodology that aims to make it quick and painless to enact large, sweeping changes in a codebase.

Tests are declared inside of a macro defined in tests/snapshot_tests.rs. Once a test has been declared, run:

env UPDATE_EXPECT=1 cargo test -p typeshare-core

This will generate the the folder for the new test (inside of data/tests) along with starter files inside of it. Save whatever Rust source input you'd like to test in the input.rs file. Then, run the command again:

env UPDATE_EXPECT=1 cargo test -p typeshare-core

The various output files will be updated with typeshare's current output for the given input. If you're happy with the output, move on; if not, hack on typeshare until the output makes sense, re-running the above command each time you'd like to update the expected output.

The test suite can of course be run normally without updating any expectations:

cargo test -p typeshare-core

If you find yourself needing to update expectations for a specific test only, run the following (subsituting the name of your test in for the last arg):

env UPDATE_EXPECT=1 cargo test -p typeshare-core --test snapshot_tests -- can_handle_serde_rename_all::swift

The data stored in the snapshot test files is typeshare's output, unmodified.

This will write output_formatted.(ts|kt|swift) files next to each stored snapshot file.


~37K SLoC