• Stars
    star
    2,393
  • Rank 19,227 (Top 0.4 %)
  • Language
    Rust
  • License
    Apache License 2.0
  • Created about 2 years ago
  • Updated 2 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

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

Typeshare

Crate Status
typeshare crates.io version crate documentation MSRV crates.io downloads
typeshare-core crates.io version crate documentation MSRV crates.io downloads
typeshare-annotation crates.io version crate documentation MSRV crates.io downloads
typeshare-cli crates.io version MSRV crates.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 the serde library, Typeshare is a tool that converts your Rust types into their equivalent forms in Swift, Go**, Kotlin, Scala and Typescript, keeping your 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. See here for more details.

Installation

To install the CLI (Command Line Interface):

cargo install typeshare-cli

πŸ’‘Note that the console command will be typeshare, not typeshare-cli.

In your Cargo.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 the typeshare 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.kt
typeshare ./my_rust_project --lang=swift --output-file=my_swift_definitions.swift
typeshare ./my_rust_project --lang=scala --output-file=my_scala_definitions.scala
typeshare ./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]
struct MyStruct {
    my_name: String,
    my_age: u32,
}

#[typeshare]
#[serde(tag = "type", content = "content")]
enum MyEnum {
    MyVariant(bool),
    MyOtherVariant,
    MyNumber(u32),
}
// Generated Typescript definitions

export interface MyStruct {
    my_name: string;
    my_age: number;
}

export type MyEnum = 
    | { 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**

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 support is experimental. Enable the go feature when installing typeshare-cli if you want to use it.

Credits

Made with ❀️ and β˜• by the 1Password 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 our other repository to get a 1Password Teams account on us:

✨1Password for Open Source Projects

License

Licensed under either of Apache License, Version 2.0 or MIT license at your option.
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in this crate by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

More Repositories

1

1password-teams-open-source

Get a free 1Password Teams membership for your open source project
1,562
star
2

arboard

A clipboard for Rust
Rust
640
star
3

onepassword-operator

The 1Password Connect Kubernetes Operator provides the ability to integrate Kubernetes Secrets with 1Password. The operator also handles autorestarting deployments when 1Password items are updated.
Go
531
star
4

shell-plugins

Seamless authentication for every tool in your terminal.
Go
519
star
5

electron-hardener

A fast and small Rust library to make Electron apps more secure.
Rust
380
star
6

srp

A set of Go functions for Secure Remote Password protocol implementation in 1Password Teams
Go
348
star
7

terraform-provider-onepassword

Use the 1Password Terraform Provider to reference, create, or update items in your 1Password Vaults.
Go
323
star
8

op-vscode

1Password for VS Code
TypeScript
211
star
9

spg

1Password's Strong Password Generator - Go package
Go
202
star
10

connect-sdk-python

Python SDK for 1Password Connect
Python
200
star
11

vault-plugin-secrets-onepassword

Hashicorp Vault plugin integrates with 1Password Connect to allow for the retrieval, creation, and deletion of items stored in 1Password.
Go
193
star
12

load-secrets-action

Load secrets from 1Password into your GitHub Actions jobs
TypeScript
183
star
13

connect-sdk-go

Go SDK for 1Password Connect
Go
159
star
14

connect

Access your 1Password secrets using a 1Password Connect Server
149
star
15

scim-examples

1Password SCIM Bridge deployment examples
HCL
147
star
16

connect-sdk-js

Node SDK for 1Password Connect
TypeScript
143
star
17

passkey-rs

A framework for defining Webauthn Authenticators that support passkeys
Rust
122
star
18

ansible-onepasswordconnect-collection

The 1Password Connect collection contains modules that interact with your 1Password Connect deployment. The modules communicate with the 1Password Connect API to support Vault Item create/read/update/delete operations.
Python
112
star
19

op-js

A JS library powered by the 1Password CLI
TypeScript
92
star
20

solutions

Examples and templates from the 1Password Solutions team
Python
78
star
21

connect-helm-charts

Official 1Password Helm Charts
Smarty
76
star
22

electron-secure-defaults

Starter kit and documentation for building security conscious Electron apps
TypeScript
74
star
23

typeshare-old

Generate code in different languages from Rust type definitions for FFI interop.
Rust
70
star
24

password-rules-parser

Rust parser for the passwordrules attribute
Rust
68
star
25

sys-locale

A small and lightweight Rust library to obtain the active locale on the system.
Rust
66
star
26

burp-1password-session-analyzer

Burp plugin for the 1Password session protocol for use by security researchers. https://bugcrowd.com/agilebits
Java
51
star
27

kubernetes-secrets-injector

Go
49
star
28

check-signed-commits-action

GitHub Action to check PRs for signed commits
41
star
29

homebrew-tap

Homebrew tap to install 1Password products.
Ruby
37
star
30

install-cli-action

Install 1Password CLI into your GitHub Actions jobs.
Shell
31
star
31

op-scim-helm

Helm charts for the op-scim applications
Smarty
22
star
32

pulumi-onepassword

Pulumi provider for 1Password.
Python
16
star
33

developer-community-projects

Go
15
star
34

op-scim-gcp-marketplace

Makefile
14
star
35

events-api-elastic

Go
12
star
36

events-api-generic

Go
12
star
37

markdown-benchmarks

Benchmarking markdown libraries
C
11
star
38

events-api-splunk

Go
7
star
39

dep-report

Go
7
star
40

postman-integration-secrets-edu-ut-edition

JavaScript
7
star
41

terraform-provider-onepassword-secrets-edu-ut-edition

Go
7
star
42

ring

Fork of https://github.com/briansmith/ring
Assembly
5
star
43

secrets-orb

Shell
5
star
44

blog-ci-docker

Dockerfile for 1password/blog-ci container. Based on https://github.com/felicianotech/docker-hugo
5
star
45

onepassword-sdk-go

Go
5
star
46

onepassword-sdk-js

The official JavaScript SDK for 1Password
JavaScript
5
star
47

publicsuffix-benchmarks

Testing performance of the public suffix list libraries (https://publicsuffix.org)
Rust
4
star
48

extension-messaging

TypeScript
4
star
49

onepassword-sdk-python

Python
3
star
50

go-directequality-checker

Go
2
star
51

docusaurus-extensions

TypeScript
2
star
52

ppa

TeX
1
star