16 releases (stable)

1.10.0-beta.1 May 2, 2024
1.9.2 Apr 16, 2024
1.8.0 Feb 28, 2024
1.7.0 Aug 11, 2023
1.0.0 Nov 22, 2022

#578 in Procedural macros

Download history 118/week @ 2024-01-23 198/week @ 2024-01-30 232/week @ 2024-02-06 237/week @ 2024-02-13 147/week @ 2024-02-20 409/week @ 2024-02-27 245/week @ 2024-03-05 262/week @ 2024-03-12 250/week @ 2024-03-19 222/week @ 2024-03-26 694/week @ 2024-04-02 270/week @ 2024-04-09 702/week @ 2024-04-16 352/week @ 2024-04-23 440/week @ 2024-04-30 233/week @ 2024-05-07

1,788 downloads per month
Used in typeshare-cli


10K SLoC

Rust 5K SLoC // 0.0% comments Swift 2K SLoC // 0.0% comments Go 1.5K SLoC // 0.0% comments Scala 780 SLoC // 0.1% comments Kotlin 734 SLoC // 0.1% comments TypeScript 338 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.


~29K SLoC