npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

@zorsh/cli

v0.1.4

Published

Zorsh generator for Rust

Readme

zorsh-gen-rs 🦀 → 📜

Status Stability

A code generator that turns Rust's Borsh structs into Zorsh TypeScript schemas, using Rust itself as the schema language.

zorsh-gen-rs takes your existing Rust types and automatically generates Zorsh schemas for TypeScript. One command, zero maintenance, complete type safety.

Features

  • 🎯 Use Rust as Your Schema - No separate schema language needed. Your Rust types are your source of truth
  • 🔄 Automatic Conversion - Directly generate Zorsh schemas from your Rust structs and enums
  • 🌳 Preserves Structure - Maintains your Rust module hierarchy in the generated TypeScript
  • 🔍 Deep Type Analysis - Handles complex nested types, generics, and cross-module dependencies
  • Zero Runtime Overhead - Follows Borsh's philosophy of high performance serialization
  • 🛡️ Type Safe - If it compiles in Rust, it works in TypeScript

Quick Start

# Using npx (Node.js)
npx @zorsh/cli ./src/models ./generated

# Or using pnpm
pnpm dlx @zorsh/cli ./src/models ./generated

Your Rust types:

use borsh::{BorshDeserialize, BorshSerialize};

#[derive(BorshDeserialize, BorshSerialize)]
pub struct Player {
    name: String,
    score: u32,
    inventory: HashMap<String, Vec<Item>>,
}

Automatically become Zorsh schemas:

import { b } from '@zorsh/zorsh';

export const PlayerSchema = b.struct({
    name: b.string(),
    score: b.u32(),
    inventory: b.hashMap(b.string(), b.vec(ItemSchema))
});

Why zorsh-gen-rs?

Most serialization formats force you to define your data structures twice: once in your schema language (like .proto files for Protocol Buffers or SDL for GraphQL), and again in your programming language. With Borsh, your data structures are already defined in Rust - that's where they live. zorsh-gen-rs recognizes this and lets your existing Rust types act as the schema language for Zorsh, the TypeScript implementation of Borsh.

No duplicate definitions. No schema syncing. No extra maintenance. Just:

  1. No Schema Maintenance - Your Rust types are your schema. No need to maintain separate schema files
  2. Compiler-Verified - If your Rust types compile, your schemas are valid
  3. IDE Support - Get full IDE support, type checking, and refactoring tools for your schemas
  4. Ecosystem Support - Use the full power of Rust's type system and module system

Installation

Choose the installation method that works best for your workflow:

Node.js / npm (Recommended for TypeScript projects)

# Install globally with npm
npm install -g @zorsh/cli

# Install as a dev dependency in your project
npm install --save-dev @zorsh/cli

# Or use without installing
npx @zorsh/cli
pnpm dlx @zorsh/cli

Cargo (Recommended for Rust projects)

# Install from crates.io
cargo install zorsh-gen-rs

# Or build from source
git clone https://github.com/r-near/zorsh-gen-rs
cd zorsh-gen-rs
cargo install --path .

Script Installers

# Unix-like systems (Linux, macOS)
curl --proto '=https' --tlsv1.2 -LsSf https://github.com/r-near/zorsh-gen-rs/releases/latest/download/zorsh-gen-rs-installer.sh | sh

# Windows PowerShell
powershell -ExecutionPolicy Bypass -c "irm https://github.com/r-near/zorsh-gen-rs/releases/latest/download/zorsh-gen-rs-installer.ps1 | iex"

Package Managers

# Homebrew (macOS and Linux)
brew install r-near/tap/zorsh-gen-rs

Manual Installation

Pre-built binaries are available for the following platforms:

  • macOS (Apple Silicon, Intel)
  • Windows (x64)
  • Linux (x64, ARM64)

Download the appropriate binary for your platform from the releases page.

Usage

Command Line

# Basic usage
zorsh-gen-rs <input-dir> <output-dir>

# With options
zorsh-gen-rs --flat-output --only-annotated ./src/models ./generated

As a Library

use zorsh_gen_rs::{ZorshGen, Config};

let config = Config::default();
let generator = ZorshGen::new(config);

// Convert a directory
generator.convert("./src/models", "./generated")?;

// Or convert a string
let zorsh_code = zorsh_gen_rs::convert_str(rust_code)?;

Supported Types

  • Primitives: All Rust numeric types (u8 through u128, i8 through i128, f32, f64)
  • Strings: String and &str
  • Collections: Vec<T>, [T; N], HashMap<K, V>
  • Options: Option<T>
  • Custom Types: Structs and Enums (including complex nested types)

Module Structure

zorsh-gen-rs preserves your Rust module structure in the generated TypeScript:

src/
  models/
    player.rs
    items/
      mod.rs
      weapon.rs

Becomes:

generated/
  models/
    player.ts
    items/
      index.ts
      weapon.ts

Configuration

let config = Config {
    // Only process structs with #[derive(BorshSerialize)]
    only_annotated: true,
    
    // Skip certain paths
    ignored_patterns: vec!["tests/", "examples/"],
    
    // Output structure (nested or flat)
    output_structure: OutputStructure::Nested,
};

Contributing

Contributions are welcome! Before you start:

  • Check out our Technical Documentation for a deep dive into the codebase
  • Feel free to:
    • Report bugs
    • Suggest features
    • Submit pull requests

Related Projects

  • Zorsh - The TypeScript implementation of Borsh
  • Borsh - The original Rust binary serialization format

License

MIT