18 releases

✓ Uses Rust 2018 edition

0.5.1 Apr 5, 2019
0.5.0 Mar 31, 2019
0.4.2 Mar 1, 2019
0.4.0 Aug 11, 2018
0.0.1 Jul 30, 2017

#21 in Encoding

Download history 3179/week @ 2019-05-02 3341/week @ 2019-05-09 4584/week @ 2019-05-16 5695/week @ 2019-05-23 5287/week @ 2019-05-30 6051/week @ 2019-06-06 7000/week @ 2019-06-13 6624/week @ 2019-06-20 6903/week @ 2019-06-27 8413/week @ 2019-07-04 9014/week @ 2019-07-11 9436/week @ 2019-07-18 9544/week @ 2019-07-25 10172/week @ 2019-08-01 11376/week @ 2019-08-08

15,356 downloads per month
Used in 122 crates (57 directly)

MIT/Apache

96KB
3K SLoC

Rusty Object Notation

Build Status Crates.io Docs Gitter

RON is a simple readable data serialization format that looks similar to Rust syntax. It's designed to support all of Serde's data model, so structs, enums, tuples, arrays, generic maps, and primitive values.

Example

GameConfig( // optional struct name
    window_size: (800, 600),
    window_title: "PAC-MAN",
    fullscreen: false,
    
    mouse_sensitivity: 1.4,
    key_bindings: {
        "up": Up,
        "down": Down,
        "left": Left,
        "right": Right,
        
        // Uncomment to enable WASD controls
        /*
        "W": Up,
        "A": Down,
        "S": Left,
        "D": Right,
        */
    },
    
    difficulty_options: (
        start_difficulty: Easy,
        adaptive: false,
    ),
)

Why RON?

Example in JSON

{
   "materials": {
        "metal": {
            "reflectivity": 1.0
        },
        "plastic": {
            "reflectivity": 0.5
        }
   },
   "entities": [
        {
            "name": "hero",
            "material": "metal"
        },
        {
            "name": "monster",
            "material": "plastic"
        }
   ]
}

Notice these issues:

  1. Struct and maps are the same - random order of exported fields
    • annoying and inconvenient for reading
    • doesn't work well with version control - quoted field names
    • too verbose - no support for enums
  2. No trailing comma allowed
  3. No comments allowed

Same example in RON

Scene( // class name is optional
    materials: { // this is a map
        "metal": (
            reflectivity: 1.0,
        ),
        "plastic": (
            reflectivity: 0.5,
        ),
    },
    entities: [ // this is an array
        (
            name: "hero",
            material: "metal",
        ),
        (
            name: "monster",
            material: "plastic",
        ),
    ],
)

The new format uses (..) brackets for heterogeneous structures (classes), while preserving the {..} for maps, and [..] for homogeneous structures (arrays). This distinction allows us to solve the biggest problem with JSON.

Here are the general rules to parse the heterogeneous structures:

class is named? fields are named? what is it? example
no no tuple (a, b)
yes/no no tuple struct Name(a, b)
yes no enum value Variant(a, b)
yes/no yes struct (f1: a, f2: b,)

Specification

There is a very basic, work in progress specification available on the wiki page. A more formal and complete grammar is available here.

Appendix

Why not XML?

  • too verbose
  • unclear how to treat attributes vs contents

Why not YAML?

  • significant white-space
  • specification is too big

Why not TOML?

  • alien syntax
  • absolute paths are not scalable

Why not XXX?

  • if you know a better format, tell me!

Tooling

Sublime Text: https://packagecontrol.io/packages/RON

Vim: https://github.com/ron-rs/ron.vim

License

RON is dual-licensed under Apache-2.0 and MIT.

Dependencies

~1–1.5MB
~32K SLoC