Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up

Typeshare is the ultimate tool for synchronizing your type definitions between Rust and other languages for seamless FFI.

License

Apache-2.0, MIT licenses found

Licenses found

Apache-2.0
LICENSE-APACHE
MIT
LICENSE-MIT
NotificationsYou must be signed in to change notification settings

1Password/typeshare

Repository files navigation

CrateStatus
typesharecrates.io versioncrate documentationMSRVcrates.io downloads
typeshare-corecrates.io versioncrate documentationMSRVcrates.io downloads
typeshare-annotationcrates.io versioncrate documentationMSRVcrates.io downloads
typeshare-clicrates.io versionMSRVcrates.io downloads

One tool to rule the types,

One tool to FFI them,

One tool to parse your Rust,

And in the darkness, compile them 💍

Do you like manually managing types that need to be passed through an FFI layer, so that your code doesn't archaically break at runtime? Be honest, nobody does. Typeshare is here to take that burden away from you! Leveraging the power of theserde library, Typeshare is a tool that converts yourRust types into their equivalent forms in Swift, Go**, Python**, Kotlin, Scala and Typescript, keepingyour cross-language codebase in sync. With automatic implementation for serialization and deserialization on both sides of the FFI, Typeshare does all the heavy lifting for you. It can even handle generics and convert effortlessly between standard libraries in different languages!

**A few caveats. Seehere for more details.

Installation

To install the CLI (Command Line Interface):

cargo install typeshare-cli

💡Note that the console command will betypeshare, nottypeshare-cli.

In yourCargo.toml, under[dependencies]:

typeshare ="1.0.0"

Using Typeshare

We've put together a book that documents (almost) everything you can do.

📚Read the Typeshare book here!

To generate FFI definitions for a target language, run thetypeshare command and specify the directory containing your rust code, the language you would like to generate for, and the file to which your generated definitions will be written:

typeshare ./my_rust_project --lang=kotlin --output-file=my_kotlin_definitions.kttypeshare ./my_rust_project --lang=swift --output-file=my_swift_definitions.swifttypeshare ./my_rust_project --lang=scala --output-file=my_scala_definitions.scalatypeshare ./my_rust_project --lang=typescript --output-file=my_typescript_definitions.ts

Annotating Types

Include the#[typeshare] attribute with any struct or enum you define to generate definitions for that type in the selected output language.

// Rust type definitions#[typeshare]structMyStruct{my_name:String,my_age:u32,}#[typeshare]#[serde(tag ="type", content ="content")]enumMyEnum{MyVariant(bool),MyOtherVariant,MyNumber(u32),}
// Generated Typescript definitionsexportinterfaceMyStruct{my_name:string;my_age:number;}exporttypeMyEnum=|{type:"MyVariant",content:boolean}|{type:"MyOtherVariant",content:undefined}|{type:"MyNumber",content:number};

Getting Help

Are you getting weird deserialization issues? Did our procedural macro throw a confusing error at you? Are you trying to contribute and our existing codebase is confusing? (probably true) Did you have another problem not enumerated in this reductive list? Please open an issue in this repository and the 1Password team would be happy to help! That's what we're here for!

A Quick Refresher on Supported Languages

  • Kotlin
  • Scala
  • Swift
  • Typescript
  • Go**
  • Python** (see list of limitationshere)

If there is a language that you want Typeshare to generate definitions for, you can either:

  1. Open an issue in this repository requesting your language of choice.
  2. Implement support for that language and open a PR with your implementation. We would be eternally grateful! 🙏

** Right now, Go and Python support is experimental. Enable thego orpython features, respectively, when installing typeshare-cli if you want to use these.

Credits

Made with ❤️ and ☕ by the1Password team.

Get a free 1Password account for your open source project

Does your team need a secure way to manage passwords and other credentials for your open source project? Head on over to ourother repository to get a 1Password Teams account on us:

1Password for Open Source Projects

License

Licensed under either ofApache License, Version2.0 orMIT license at your option.
Unless you explicitly state otherwise, any contribution intentionally submittedfor inclusion in this crate by you, as defined in the Apache-2.0 license, shallbe dual licensed as above, without any additional terms or conditions.

About

Typeshare is the ultimate tool for synchronizing your type definitions between Rust and other languages for seamless FFI.

Topics

Resources

License

Apache-2.0, MIT licenses found

Licenses found

Apache-2.0
LICENSE-APACHE
MIT
LICENSE-MIT

Stars

Watchers

Forks

Packages

No packages published

[8]ページ先頭

©2009-2025 Movatter.jp