diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 09:22:09 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 09:22:09 +0000 |
commit | 43a97878ce14b72f0981164f87f2e35e14151312 (patch) | |
tree | 620249daf56c0258faa40cbdcf9cfba06de2a846 /third_party/rust/ron/README.md | |
parent | Initial commit. (diff) | |
download | firefox-upstream.tar.xz firefox-upstream.zip |
Adding upstream version 110.0.1.upstream/110.0.1upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'third_party/rust/ron/README.md')
-rw-r--r-- | third_party/rust/ron/README.md | 171 |
1 files changed, 171 insertions, 0 deletions
diff --git a/third_party/rust/ron/README.md b/third_party/rust/ron/README.md new file mode 100644 index 0000000000..6ed5908232 --- /dev/null +++ b/third_party/rust/ron/README.md @@ -0,0 +1,171 @@ +# Rusty Object Notation + +[![CI](https://github.com/ron-rs/ron/actions/workflows/ci.yaml/badge.svg)](https://github.com/ron-rs/ron/actions/workflows/ci.yaml) +[![codecov](https://img.shields.io/codecov/c/github/ron-rs/ron/codecov?token=x4Q5KA51Ul)](https://codecov.io/gh/ron-rs/ron) +[![Crates.io](https://img.shields.io/crates/v/ron.svg)](https://crates.io/crates/ron) +[![MSRV](https://img.shields.io/badge/MSRV-1.56.0-orange)](https://github.com/ron-rs/ron) +[![Docs](https://docs.rs/ron/badge.svg)](https://docs.rs/ron) +[![Matrix](https://img.shields.io/matrix/ron-rs:matrix.org.svg)](https://matrix.to/#/#ron-rs:matrix.org) + +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](https://serde.rs/data-model.html), so +structs, enums, tuples, arrays, generic maps, and primitive values. + +## Example + +```rust,ignore +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 + +```json +{ + "materials": { + "metal": { + "reflectivity": 1.0 + }, + "plastic": { + "reflectivity": 0.5 + } + }, + "entities": [ + { + "name": "hero", + "material": "metal" + }, + { + "name": "monster", + "material": "plastic" + } + ] +} +``` + +### Same example in RON + +```rust,ignore +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", + ), + ], +) +``` + +Note the following advantages of RON over JSON: + +* trailing commas allowed +* single- and multi-line comments +* field names aren't quoted, so it's less verbose +* optional struct names improve readability +* enums are supported (and less verbose than their JSON representation) + +## RON syntax overview + +* Numbers: `42`, `3.14`, `0xFF`, `0b0110` +* Strings: `"Hello"`, `"with\\escapes\n"`, `r#"raw string, great for regex\."#` +* Booleans: `true`, `false` +* Chars: `'e'`, `'\n'` +* Optionals: `Some("string")`, `Some(Some(1.34))`, `None` +* Tuples: `("abc", 1.23, true)`, `()` +* Lists: `["abc", "def"]` +* Structs: `( foo: 1.0, bar: ( baz: "I'm nested" ) )` +* Maps: `{ "arbitrary": "keys", "are": "allowed" }` + +> **Note:** Serde's data model represents fixed-size Rust arrays as tuple (instead of as list) + +## Quickstart + +### `Cargo.toml` + +```toml +[dependencies] +ron = "0.8" +serde = { version = "1", features = ["derive"] } +``` + +### `main.rs` + +```rust +use serde::{Deserialize, Serialize}; + +#[derive(Debug, Deserialize, Serialize)] +struct MyStruct { + boolean: bool, + float: f32, +} + +fn main() { + let x: MyStruct = ron::from_str("(boolean: true, float: 1.23)").unwrap(); + + println!("RON: {}", ron::to_string(&x).unwrap()); +} +``` + +## Tooling + +| Editor | Plugin | +| ------------ | ----------------------------------------------------------- | +| IntelliJ | [intellij-ron](https://github.com/ron-rs/intellij-ron) | +| VS Code | [a5huynh/vscode-ron](https://github.com/a5huynh/vscode-ron) | +| Sublime Text | [RON](https://packagecontrol.io/packages/RON) | +| Atom | [language-ron](https://atom.io/packages/language-ron) | +| Vim | [ron-rs/ron.vim](https://github.com/ron-rs/ron.vim) | +| EMACS | [emacs-ron] | + +[emacs-ron]: https://chiselapp.com/user/Hutzdog/repository/ron-mode/home + +## Specification + +There is a very basic, work in progress specification available on +[the wiki page](https://github.com/ron-rs/ron/wiki/Specification). +A more formal and complete grammar is available [here](docs/grammar.md). + + +## License + +RON is dual-licensed under Apache-2.0 and MIT. + +Any contribution intentionally submitted for inclusion in the work must be provided under the same dual-license terms. |