Rust developers can now generate consistent type schema with Typeshare

Rust developers can now generate consistent type schema with Typeshare

Jason Harris by Jason Harris on

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 (user interface) 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.

But 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.

You have 100 words to excite Rustaceans about this. Go:

Jane: 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?

Jane: 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?

Jane: 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. For those who have requested this to become open source, thank you for your patience!

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! If someone wants to fix a bug or expand Typeshare to cover a new language or use case, they have the power to do that. The scrutiny will also give our team better insight into our blind spots so we can better address any issues that come up.

What’s next?

Jane: 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. If anyone wants to try it out in its current state, it’s on our “repl” branch in the Git repository. Eventually, we want to make it a public site you can visit instead of a server you have to run locally.

There are still a lot of improvements we want to make to Typeshare down the road. One current limitation of our tool is that it can’t recognize types that get generated within macros, and we’re currently figuring out how to solve that.

Finally, 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.

Join us live for Typeshare Office Hours!

If you have questions or feedback for the Typeshare team, we’re here to help. Join Jane and myself for a 30-minute Q&A session via Zoom on Tuesday, December 6 at 12-12:30 PM ET. We look forward to seeing you and answering any questions you may have.

Typeshare Q&A Session

Questions or feedback for the Typeshare team? We’re here to help. Join Jane and Jason for a 30-minute Q&A session via Zoom on Tuesday, December 6 at 12-12:30 PM ET.
Join the Q&A session

Principal Platform Evangelist

Jason Harris - Principal Platform Evangelist Jason Harris - Principal Platform Evangelist

Tweet about this post