Crates.io | rsn |
lib.rs | rsn |
version | 0.2.0 |
source | src |
created_at | 2023-03-28 16:45:45.370714 |
updated_at | 2024-10-31 16:12:59.163085 |
description | A Rust-inspired, human-readable object notation. |
homepage | |
repository | https://github.com/khonsulabs/rsn |
max_upload_size | |
id | 823221 |
size | 304,718 |
This crate is very early in development. Please report any issues on our GitHub.
A UTF-8 based text format that looks very similar to valid Rust code. This format adheres closely to Rust's lexical rules
no_std
supportThis crate supports no_std
targets that support the alloc
crate.
ExampleStruct {
integers: [42, 0xFF, 0o77, 0b101],
floats: [42., 3.14, 1e10],
bools: [true, false],
chars: ['a', '\''],
string: "Hello, World!",
raw_string: r#"I said, "Hello, World!""#,
bytes: [b'a', b'\''],
byte_string: b"Hello, World!",
raw_byte_string: br#"I said, "Hello, World!""#,
named_map: StructLike {
field: 42,
},
named_tuple: TupleLike(42),
r#raw_identifiers: true,
array: [1, 2, 3],
tuple: (1, 2, 3),
map: {
"a": 1,
"b": 2,
},
}
Integers (42
, 0xFF
, 0o77
, 0b101
)
Floats (42.
, 3.14
)
Bool (true
, false
)
Character ('a'
, '\''
)
Byte (b'a'
, b'\''
)
String ("hello, world"
)
Raw Strings (r#"They said, "Hello World!""#
)
Byte Strings (b"hello, world"
)
Named
r#foo
)Map
<Value>: <Value>
pairs, delimited by commaTuple (empty tuple = Unit)
<Value>
s, delimited by commaArray
<Value>
s, delimited by commaComments //
and /* */
Potential Extensions via #[] syntax
#[foo(...), bar = ...,]
Ron is a great format. There were a few design decisions that led to this very-similar-yet-not-the-same format being invented:
ron
differentiates between Tuples and Lists, while rsn
treats all
sequences the same.ron
uses a different syntax for structures and maps. rsn
uses the same
syntax for both concepts.ron
has special support for Option<T>
. rsn
treats Option<T>
like any
other enum.ron
's parsing rules are close but not the same as Rust, while rsn
attempts
to match implementations:
_
in float literalsbase64
encoded strings for byte values.The syntax differs from valid Rust code for:
Red
vs Color::Red
use Color::*
is present.+inf
/-inf
/+NaN
/-NaN
.
f64::INFINITY
is being
considered.The rules for parsing literals should match Rust's rules as closely as possible.