8000 Specification · rson-rs/rson Wiki · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content
Alexander Mescheryakov edited this page Sep 29, 2017 · 3 revisions

Welcome to the RSON wiki, which tries to give a very basic specification for the RSON format.

Structs

Structs with named fields can optionally start with their type name. The fields of the struct are wrapped with braces ({ and }). Trailing commas are (like everywhere else) allowed.

Examples

{
    field_name: 3.4,
    b: 'b',
}
{a: false,}
Vector2 {
    x: 42.0,
    y: 5.0,
}

An empty struct with braces at the end:

struct Empty {}

Note that it gets deserialized like this:

Empty {}

As you can see, there is no comma, but two braces at the end. This is not true for unit structs, which are specified below.

Unit structs

Unit structs have two representations: Their name or ().

They're defined like this:

struct Unit;

Examples

Unit
()

Unit value

The unit value (()) has the same representation in RSON.

Examples

()

Tuple structs

A tuple struct can be defined like this:

struct TupleStruct(f32, bool, String);

The RSON version looks pretty much the same, but the name is optional.

Examples

TupleStruct(3.4, false, "Hey there!")
(
    4.3,
    true,
    "Looks different, doesn't it?",
)

Optionals

What serde describes as optional is just the representation of Rust's Option. RSON again stays very close to Rust, so it's just Some(Value) or None.

Examples

Some(3.1415926535)
None

Lists

Collections of values with a variable element number are represented with [ and ] around them, separated by commas. Please note that serde handles fixed-size arrays as tuples, so this section is only valid for types like &[u32] and Vec<bool>, but not for [f32; 3].

Lists are homogeneous, so all elements have the same type.

Examples

[1, 2, 3,]
[
    22,
    26,
    34,
    41,
    46,
    56,
]

Maps

A map looks similar to a struct, but the keys are also values instead of identifiers.

Examples

{
    "monkey": "mesh/suzanne.obj",
}
{
    'a': 97,
    'd': 100,
}

Comments

One-line comments are denoted by //, wherever this appears indicates the rest of the line is a comment. Block comments are represented with /* and */, any text between them is a comment. Block comments can be nested.

Examples

// This is a comment.
{
    field_name: 3.4, //This is another comment.
    b: 'b',
}
/* This is a block comment. */
{
    field_name: 3.4,
/*
    b: 'b', /*This is
              another comment*/
*/
}
Clone this wiki locally
0