Rust Developers Can Now Generate Consistent Type Schema with Typeshare
Archival copy of an article originally published on 1Password Blog. All content written by Jason Harris.
Today, 1Password is making Typeshare publicly available as an open-source project to help Rust developers generate consistent type schema across multiple languages. With Typeshare, developers can now create FFI (foreign function interfaces) with confidence.
What problem does Typeshare solve?
We often write code in another language and have Rust call that code. For example, 1Password is powered by a Rust framework built from the ground up to be highly performant and secure, with a separate frontend to display the UI on various platforms.
Decoupling the display code from our business logic gives us cross-platform consistency while also letting 1Password look great on any device. But the frontends are written in a different language, so we use a foreign function interface to communicate with the frontends.
We needed to ensure the data we gave to the frontend was understood correctly — if the data types between the languages weren’t in sync, it would result in a host of problems. Typeshare was the solution, and today it helps our backend developers rapidly develop new features and fixes without fear of breaking consistency with our display code.
I spoke with Jane Lewis, a developer on our Product Frameworks and Tooling team, about why she’s excited for the release of Typeshare.
Q&A with Jane Lewis, Product Frameworks and Tooling
You have 100 words to excite Rustaceans about this. Go:
Typeshare is a battle-tested, home-grown tool that enables seamless synchronization of your shared data types across languages. It integrates with the serde library for serialization and we’ve worked hard for it to be both simple and flexible. Under the hood, we use the syn library to parse your annotated Rust types and generate type definitions for each language you need, via our handy CLI.
We even support generic types and custom type conversions you can define. This tool has been the backbone for developing across multiple platforms, and we’re beyond enthused to see what others build with it!
What motivated the team to release this as open source?
Supporting open-source work and giving back to our community is a huge part of what we do at 1Password. Since we use so many open-source frameworks to make our app the best it can be, it seems only fair that we try to open-source as much of our internal work as we can, so others can use it in their projects.
In particular, a lot of people were interested in Typeshare after we talked about it in our behind-the-scenes look at 1Password for Linux.
What most excites you and the rest of the team about the release?
We’re excited to be getting this out to the public! We actually released a very primitive prototype of Typeshare years ago, but since it changed so much between then and now, we’ve had to find an opportune time to pause active development to make time for a public release.
Another exciting (and slightly terrifying) part of any open-sourcing effort is knowing you’re suddenly going to get a lot more eyes on your codebase. We’ll no doubt get scrutiny over bugs or unimplemented features. But it’s exciting because now, anyone can help make the tool better!
What’s next?
We’ve been working on a real-time REPL for Typeshare! This is both a cool demo and a playground for developers to mess around in. There are still a lot of improvements we want to make to Typeshare down the road. And we have more internal Rust crates that are in the pipeline for a public release, so stay tuned!
Get started with Typeshare
Typeshare is on crates.io and can be integrated with your project as fast as you can run cargo install typeshare-cli and add typeshare = "1" to your dependencies. The source code is available for anyone to dig through.