Skip to content
Arne K. (TRC-Loop) edited this page Nov 14, 2026 · 5 revisions

rustyon

rustyon is a Go implementation of Rusty Object Notation (RON), the human-readable serialization format used in the Rust ecosystem. It is an independent implementation and is not affiliated with the ron-rs project.

// Read and write files like this from Go.
#![enable(implicit_some)]
GameConfig(
    window_size: (800, 600),
    window_title: "Rusty Game",
    difficulty: Hard,
    spawn: Circle(radius: 2.5),
    key_bindings: {"up": Up, "down": Down},
)

Features

  • Marshal and Unmarshal with an encoding/json style API, plus MarshalIndent, a streaming Encoder and Decoder, and Marshaler / Unmarshaler interfaces.
  • Rust naming by default. Go field names become snake_case (MaxHP is max_hp), so Go structs line up with Rust structs without tags. Other strategies (camelCase, PascalCase, kebab-case, ...) can be set per call or per struct with rename_all. Struct tags support renaming, omitempty, omitzero, flatten, -, struct names and tuple structs.
  • Layout control. PrettyConfig mirrors ron-rs: compact lists, depth limit, escaped non-ASCII, numbered list elements. See Pretty Printing.
  • Raw values. rustyon.Raw keeps one value as text for later decoding; UnmarshalAs[T] returns the value directly.
  • Option and the RON extensions. Pointers map to Option (None / Some(v)). The encoder can write implicit_some and unwrap_newtypes output; the decoder always accepts both forms.
  • Rust enums on Go interfaces. Register variants once and Circle(radius: 1.0) decodes into your Circle type. Unit, tuple, struct and newtype variants are supported, as are serde's internally tagged, adjacently tagged and untagged forms, and data-less enums can map onto Go constants.
  • Dynamic Value tree for documents of unknown shape, including 128-bit integers, ordered maps and struct names.
  • Formatter that keeps comments, like gofmt for .ron files. It keeps number spellings, raw strings and your choice between one-line and multi-line collections.
  • Full ron-rs grammar: raw strings, byte strings, byte literals, nested block comments, number suffixes, raw identifiers, ranges and #![enable(...)] attributes. The parser matches ron-rs 0.12.3 exactly, checked by a differential test suite against a Rust oracle.
  • Comment-preserving edits. ParseEditable changes, adds and deletes values by path (users[0].name) and leaves comments, number spellings and layout alone. See Editing.
  • JSON conversion in the ronjson package, and a rustyon CLI to format, validate, query (get) and convert files to and from JSON, YAML and TOML, with file:line:col errors that show the source line and a caret.
  • Zero dependencies, Go 1.24 or newer.

Install

go get github.com/peltonapp/rustyon-go

The module path ends in rustyon-go, but the package name is rustyon:

import "github.com/peltonapp/rustyon-go" // package rustyon

err := rustyon.Unmarshal(data, &cfg)

The JSON helpers live in a sub package:

import "github.com/peltonapp/rustyon-go/ronjson"

The command line tool installs with:

go install github.com/peltonapp/rustyon-go/cmd/rustyon@latest

The CLI is a separate Go module, so its YAML and TOML dependencies never reach your build. See CLI for install details.

A first taste

type Config struct {
    WindowTitle string   // matches window_title
    WindowSize  [2]int   // matches (800, 600)
    MaxFPS      *int     // Option<u32>: None or Some(60)
    Tags        []string `ron:"labels,omitempty"`
}

var c Config
err := rustyon.Unmarshal(data, &c)

out, err := rustyon.MarshalIndent(c, "", "    ")

Getting Started walks through the API step by step.

Pages

Page What it covers
Getting Started Unmarshal, Marshal, MarshalIndent, MarshalWith, Encoder and Decoder with all their options
Type Mapping How every Go type maps to RON and back, decoding into any, custom marshalers, Raw values, UnmarshalAs
Struct Tags Field naming strategies (camelCase, rename_all, ...), ron:"..." tags, flatten, tuple structs, newtypes, embedded structs
Enums Rust enums as Go interfaces, RegisterEnum, internally tagged, adjacently tagged and untagged enums, RegisterUnitEnum, registries
Pretty Printing PrettyConfig and MarshalWithConfig: compact lists, depth limit, escaped non-ASCII, custom indent and line breaks
Value Tree Parse, ParseDocument and the dynamic Value types
Formatter Format and FormatIndent layout rules with before and after examples
Editing ParseEditable and Editable: change values, add and delete fields in place while keeping comments and layout
CLI The rustyon command: fmt, validate, get, and conversion to and from JSON, YAML and TOML
JSON Conversion The ronjson package and what is lost on the way to JSON
RON Syntax Reference of the RON grammar this library accepts
Errors Every error type and how to inspect it with errors.As
Performance Benchmarks and performance notes

Links

Clone this wiki locally