Repository navigation
Mercury v0.1.0 - Initial Release
Mercury is a production-ready code generation tool that automatically generates PureScript type definitions and Argonaut JSON codecs from annotated Rust types.
Published Crates
- mercury-derive v0.1.0 - crates.io
- cargo-mercury v0.1.0 - crates.io
- cargo-mercury-cli v0.1.0 - crates.io
Quick Start
Installation
# Install CLI globally
cargo install cargo-mercury-cliUsage
# Generate PureScript types from Rust
mercury generateFeatures
- Automatic type conversion - Rust → PureScript type mapping
- Full serde support - Handles
rename_all,rename,skip, and other serde attributes - Type-safe JSON codecs - Generates Argonaut
EncodeJsonandDecodeJsoninstances - Cross-module imports - Automatically generates import statements for type dependencies
- Advanced type mapping - Supports
Option<T>,Vec<T>,DateTime,Uuid, and nested types - Multi-module organization - Outputs organized by source file structure
- Deterministic output - Byte-for-byte identical on repeated runs (perfect for git)
📖 Documentation
- README - Getting started guide
- TESTING.md - Test documentation
- PUBLISHING.md - Publishing guide
Testing
- 47 tests total (45 unit + 2 integration)
- 100% pass rate
- Comprehensive coverage of parser, codegen, and codec generation
📋 Type Mapping
| Rust Type | PureScript Type |
|---|---|
i32, i64 |
Int |
f32, f64 |
Number |
bool |
Boolean |
String |
String |
Option<T> |
Maybe T |
Vec<T> |
Array T |
chrono::DateTime<Utc> |
String (ISO 8601) |
🔧 Requirements
- Rust 1.85+ (uses edition 2024 features)
- PureScript 0.15+ (for frontend)
- Spago (PureScript package manager)
- Argonaut (PureScript JSON library)
Example
Rust:
use mercury_derive::mercury;
use serde::{Deserialize, Serialize};
#[mercury]
#[derive(Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct CreateUserRequest {
pub user_name: String,
pub email: String,
pub is_active: bool,
}Generated PureScript:
newtype CreateUserRequest = CreateUserRequest
{ userName :: String
, email :: String
, isActive :: Boolean
}
instance decodeCreateUserRequest :: DecodeJson CreateUserRequest
instance encodeCreateUserRequest :: EncodeJson CreateUserRequestAcknowledgments
Mercury was initially developed as part of Merchant Tech to solve the problem of keeping Rust backend types in sync with PureScript frontend types.
License
Licensed under:
- MIT license (LICENSE-MIT)
Full Changelog: https://github.com/lethalgem/mercury/commits/v0.1.0