143 lines
15 KiB
HTML
143 lines
15 KiB
HTML
<!DOCTYPE html><html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><meta name="generator" content="rustdoc"><meta name="description" content="Rusty Object Notation"><title>ron - Rust</title><script>if(window.location.protocol!=="file:")document.head.insertAdjacentHTML("beforeend","SourceSerif4-Regular-6b053e98.ttf.woff2,FiraSans-Regular-0fe48ade.woff2,FiraSans-Medium-e1aa3f0a.woff2,SourceCodePro-Regular-8badfe75.ttf.woff2,SourceCodePro-Semibold-aa29a496.ttf.woff2".split(",").map(f=>`<link rel="preload" as="font" type="font/woff2" crossorigin href="../static.files/${f}">`).join(""))</script><link rel="stylesheet" href="../static.files/normalize-9960930a.css"><link rel="stylesheet" href="../static.files/rustdoc-42caa33d.css"><meta name="rustdoc-vars" data-root-path="../" data-static-root-path="../static.files/" data-current-crate="ron" data-themes="" data-resource-suffix="" data-rustdoc-version="1.84.0 (9fc6b4312 2025-01-07)" data-channel="1.84.0" data-search-js="search-92e6798f.js" data-settings-js="settings-0f613d39.js" ><script src="../static.files/storage-59e33391.js"></script><script defer src="../crates.js"></script><script defer src="../static.files/main-5f194d8c.js"></script><noscript><link rel="stylesheet" href="../static.files/noscript-893ab5e7.css"></noscript><link rel="alternate icon" type="image/png" href="../static.files/favicon-32x32-6580c154.png"><link rel="icon" type="image/svg+xml" href="../static.files/favicon-044be391.svg"></head><body class="rustdoc mod crate"><!--[if lte IE 11]><div class="warning">This old browser is unsupported and will most likely display funky things.</div><![endif]--><nav class="mobile-topbar"><button class="sidebar-menu-toggle" title="show sidebar"></button></nav><nav class="sidebar"><div class="sidebar-crate"><h2><a href="../ron/index.html">ron</a><span class="version">0.8.1</span></h2></div><div class="sidebar-elems"><ul class="block"><li><a id="all-types" href="all.html">All Items</a></li></ul><section id="rustdoc-toc"><h3><a href="#">Sections</a></h3><ul class="block top-toc"><li><a href="#rusty-object-notation" title="Rusty Object Notation">Rusty Object Notation</a><ul><li><a href="#example" title="Example">Example</a></li><li><a href="#why-ron" title="Why RON?">Why RON?</a></li><li><a href="#limitations" title="Limitations">Limitations</a></li><li><a href="#ron-syntax-overview" title="RON syntax overview">RON syntax overview</a></li><li><a href="#quickstart" title="Quickstart">Quickstart</a></li><li><a href="#tooling" title="Tooling">Tooling</a></li><li><a href="#specification" title="Specification">Specification</a></li><li><a href="#license" title="License">License</a></li></ul></li></ul><h3><a href="#reexports">Crate Items</a></h3><ul class="block"><li><a href="#reexports" title="Re-exports">Re-exports</a></li><li><a href="#modules" title="Modules">Modules</a></li></ul></section><div id="rustdoc-modnav"></div></div></nav><div class="sidebar-resizer"></div><main><div class="width-limiter"><rustdoc-search></rustdoc-search><section id="main-content" class="content"><div class="main-heading"><h1>Crate <span>ron</span><button id="copy-path" title="Copy item path to clipboard">Copy item path</button></h1><rustdoc-toolbar></rustdoc-toolbar><span class="sub-heading"><a class="src" href="../src/ron/lib.rs.html#1-20">Source</a> </span></div><details class="toggle top-doc" open><summary class="hideme"><span>Expand description</span></summary><div class="docblock"><h2 id="rusty-object-notation"><a class="doc-anchor" href="#rusty-object-notation">§</a>Rusty Object Notation</h2>
|
||
<p><a href="https://github.com/ron-rs/ron/actions/workflows/ci.yaml"><img src="https://github.com/ron-rs/ron/actions/workflows/ci.yaml/badge.svg" alt="CI" /></a>
|
||
<a href="https://codecov.io/gh/ron-rs/ron"><img src="https://img.shields.io/codecov/c/github/ron-rs/ron/codecov?token=x4Q5KA51Ul" alt="codecov" /></a>
|
||
<a href="https://crates.io/crates/ron"><img src="https://img.shields.io/crates/v/ron.svg" alt="Crates.io" /></a>
|
||
<a href="https://github.com/ron-rs/ron"><img src="https://img.shields.io/badge/MSRV-1.64.0-orange" alt="MSRV" /></a>
|
||
<a href="https://docs.rs/ron"><img src="https://docs.rs/ron/badge.svg" alt="Docs" /></a>
|
||
<a href="https://matrix.to/#/#ron-rs:matrix.org"><img src="https://img.shields.io/matrix/ron-rs:matrix.org.svg" alt="Matrix" /></a></p>
|
||
<p>RON is a simple readable data serialization format that looks similar to Rust syntax.
|
||
It’s designed to support all of <a href="https://serde.rs/data-model.html">Serde’s data model</a>, so
|
||
structs, enums, tuples, arrays, generic maps, and primitive values.</p>
|
||
<h3 id="example"><a class="doc-anchor" href="#example">§</a>Example</h3>
|
||
<div class="example-wrap ignore"><a href="#" class="tooltip" title="This example is not tested">ⓘ</a><pre class="rust rust-example-rendered"><code>GameConfig( <span class="comment">// optional struct name
|
||
</span>window_size: (<span class="number">800</span>, <span class="number">600</span>),
|
||
window_title: <span class="string">"PAC-MAN"</span>,
|
||
fullscreen: <span class="bool-val">false</span>,
|
||
|
||
mouse_sensitivity: <span class="number">1.4</span>,
|
||
key_bindings: {
|
||
<span class="string">"up"</span>: Up,
|
||
<span class="string">"down"</span>: Down,
|
||
<span class="string">"left"</span>: Left,
|
||
<span class="string">"right"</span>: Right,
|
||
|
||
<span class="comment">// Uncomment to enable WASD controls
|
||
/*
|
||
"W": Up,
|
||
"S": Down,
|
||
"A": Left,
|
||
"D": Right,
|
||
*/
|
||
</span>},
|
||
|
||
difficulty_options: (
|
||
start_difficulty: Easy,
|
||
adaptive: <span class="bool-val">false</span>,
|
||
),
|
||
)</code></pre></div>
|
||
<h3 id="why-ron"><a class="doc-anchor" href="#why-ron">§</a>Why RON?</h3><h4 id="example-in-json"><a class="doc-anchor" href="#example-in-json">§</a>Example in JSON</h4><div class="example-wrap"><pre class="language-json"><code>{
|
||
"materials": {
|
||
"metal": {
|
||
"reflectivity": 1.0
|
||
},
|
||
"plastic": {
|
||
"reflectivity": 0.5
|
||
}
|
||
},
|
||
"entities": [
|
||
{
|
||
"name": "hero",
|
||
"material": "metal"
|
||
},
|
||
{
|
||
"name": "monster",
|
||
"material": "plastic"
|
||
}
|
||
]
|
||
}</code></pre></div><h4 id="same-example-in-ron"><a class="doc-anchor" href="#same-example-in-ron">§</a>Same example in RON</h4>
|
||
<div class="example-wrap ignore"><a href="#" class="tooltip" title="This example is not tested">ⓘ</a><pre class="rust rust-example-rendered"><code>Scene( <span class="comment">// class name is optional
|
||
</span>materials: { <span class="comment">// this is a map
|
||
</span><span class="string">"metal"</span>: (
|
||
reflectivity: <span class="number">1.0</span>,
|
||
),
|
||
<span class="string">"plastic"</span>: (
|
||
reflectivity: <span class="number">0.5</span>,
|
||
),
|
||
},
|
||
entities: [ <span class="comment">// this is an array
|
||
</span>(
|
||
name: <span class="string">"hero"</span>,
|
||
material: <span class="string">"metal"</span>,
|
||
),
|
||
(
|
||
name: <span class="string">"monster"</span>,
|
||
material: <span class="string">"plastic"</span>,
|
||
),
|
||
],
|
||
)</code></pre></div>
|
||
<p>Note the following advantages of RON over JSON:</p>
|
||
<ul>
|
||
<li>trailing commas allowed</li>
|
||
<li>single- and multi-line comments</li>
|
||
<li>field names aren’t quoted, so it’s less verbose</li>
|
||
<li>optional struct names improve readability</li>
|
||
<li>enums are supported (and less verbose than their JSON representation)</li>
|
||
</ul>
|
||
<h3 id="limitations"><a class="doc-anchor" href="#limitations">§</a>Limitations</h3>
|
||
<p>RON is not designed to be a fully self-describing format (unlike JSON) and is thus not guaranteed to work when <a href="https://docs.rs/serde/latest/serde/trait.Deserializer.html#tymethod.deserialize_any"><code>deserialize_any</code></a> is used instead of its typed alternatives. In particular, the following Serde attributes are not yet supported:</p>
|
||
<ul>
|
||
<li><code>#[serde(tag = "type")]</code>, i.e. internally tagged enums</li>
|
||
<li><code>#[serde(untagged)]</code>, i.e. untagged enums</li>
|
||
<li><code>#[serde(flatten)]</code>, i.e. flattening an inner struct into its outer container</li>
|
||
</ul>
|
||
<h3 id="ron-syntax-overview"><a class="doc-anchor" href="#ron-syntax-overview">§</a>RON syntax overview</h3>
|
||
<ul>
|
||
<li>Numbers: <code>42</code>, <code>3.14</code>, <code>0xFF</code>, <code>0b0110</code></li>
|
||
<li>Strings: <code>"Hello"</code>, <code>"with\\escapes\n"</code>, <code>r#"raw string, great for regex\."#</code></li>
|
||
<li>Booleans: <code>true</code>, <code>false</code></li>
|
||
<li>Chars: <code>'e'</code>, <code>'\n'</code></li>
|
||
<li>Optionals: <code>Some("string")</code>, <code>Some(Some(1.34))</code>, <code>None</code></li>
|
||
<li>Tuples: <code>("abc", 1.23, true)</code>, <code>()</code></li>
|
||
<li>Lists: <code>["abc", "def"]</code></li>
|
||
<li>Structs: <code>( foo: 1.0, bar: ( baz: "I'm nested" ) )</code></li>
|
||
<li>Maps: <code>{ "arbitrary": "keys", "are": "allowed" }</code></li>
|
||
</ul>
|
||
<blockquote>
|
||
<p><strong>Note:</strong> Serde’s data model represents fixed-size Rust arrays as tuple (instead of as list)</p>
|
||
</blockquote>
|
||
<h3 id="quickstart"><a class="doc-anchor" href="#quickstart">§</a>Quickstart</h3><h4 id="cargotoml"><a class="doc-anchor" href="#cargotoml">§</a><code>Cargo.toml</code></h4><div class="example-wrap"><pre class="language-toml"><code>[dependencies]
|
||
ron = "0.8"
|
||
serde = { version = "1", features = ["derive"] }</code></pre></div><h4 id="mainrs"><a class="doc-anchor" href="#mainrs">§</a><code>main.rs</code></h4>
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>serde::{Deserialize, Serialize};
|
||
|
||
<span class="attr">#[derive(Debug, Deserialize, Serialize)]
|
||
</span><span class="kw">struct </span>MyStruct {
|
||
boolean: bool,
|
||
float: f32,
|
||
}
|
||
|
||
<span class="kw">fn </span>main() {
|
||
<span class="kw">let </span>x: MyStruct = ron::from_str(<span class="string">"(boolean: true, float: 1.23)"</span>).unwrap();
|
||
|
||
<span class="macro">println!</span>(<span class="string">"RON: {}"</span>, ron::to_string(<span class="kw-2">&</span>x).unwrap());
|
||
|
||
<span class="macro">println!</span>(<span class="string">"Pretty RON: {}"</span>, ron::ser::to_string_pretty(
|
||
<span class="kw-2">&</span>x, ron::ser::PrettyConfig::default()).unwrap(),
|
||
);
|
||
}</code></pre></div>
|
||
<h3 id="tooling"><a class="doc-anchor" href="#tooling">§</a>Tooling</h3><div><table><thead><tr><th>Editor</th><th>Plugin</th></tr></thead><tbody>
|
||
<tr><td>IntelliJ</td><td><a href="https://github.com/ron-rs/intellij-ron">intellij-ron</a></td></tr>
|
||
<tr><td>VS Code</td><td><a href="https://github.com/a5huynh/vscode-ron">a5huynh/vscode-ron</a></td></tr>
|
||
<tr><td>Sublime Text</td><td><a href="https://packagecontrol.io/packages/RON">RON</a></td></tr>
|
||
<tr><td>Atom</td><td><a href="https://atom.io/packages/language-ron">language-ron</a></td></tr>
|
||
<tr><td>Vim</td><td><a href="https://github.com/ron-rs/ron.vim">ron-rs/ron.vim</a></td></tr>
|
||
<tr><td>EMACS</td><td><a href="https://chiselapp.com/user/Hutzdog/repository/ron-mode/home">emacs-ron</a></td></tr>
|
||
</tbody></table>
|
||
</div><h3 id="specification"><a class="doc-anchor" href="#specification">§</a>Specification</h3>
|
||
<p>There is a very basic, work in progress specification available on
|
||
<a href="https://github.com/ron-rs/ron/wiki/Specification">the wiki page</a>.
|
||
A more formal and complete grammar is available <a href="docs/grammar.md">here</a>.</p>
|
||
<h3 id="license"><a class="doc-anchor" href="#license">§</a>License</h3>
|
||
<p>RON is dual-licensed under Apache-2.0 and MIT.</p>
|
||
<p>Any contribution intentionally submitted for inclusion in the work must be provided under the same dual-license terms.</p>
|
||
</div></details><h2 id="reexports" class="section-header">Re-exports<a href="#reexports" class="anchor">§</a></h2><ul class="item-table"><li><div class="item-name" id="reexport.from_str"><code>pub use de::<a class="fn" href="de/fn.from_str.html" title="fn ron::de::from_str">from_str</a>;</code></div></li><li><div class="item-name" id="reexport.Deserializer"><code>pub use de::<a class="struct" href="de/struct.Deserializer.html" title="struct ron::de::Deserializer">Deserializer</a>;</code></div></li><li><div class="item-name" id="reexport.Error"><code>pub use error::<a class="enum" href="error/enum.Error.html" title="enum ron::error::Error">Error</a>;</code></div></li><li><div class="item-name" id="reexport.Result"><code>pub use error::<a class="type" href="error/type.Result.html" title="type ron::error::Result">Result</a>;</code></div></li><li><div class="item-name" id="reexport.Options"><code>pub use options::<a class="struct" href="options/struct.Options.html" title="struct ron::options::Options">Options</a>;</code></div></li><li><div class="item-name" id="reexport.to_string"><code>pub use ser::<a class="fn" href="ser/fn.to_string.html" title="fn ron::ser::to_string">to_string</a>;</code></div></li><li><div class="item-name" id="reexport.Serializer"><code>pub use ser::<a class="struct" href="ser/struct.Serializer.html" title="struct ron::ser::Serializer">Serializer</a>;</code></div></li><li><div class="item-name" id="reexport.Map"><code>pub use value::<a class="struct" href="value/struct.Map.html" title="struct ron::value::Map">Map</a>;</code></div></li><li><div class="item-name" id="reexport.Number"><code>pub use value::<a class="enum" href="value/enum.Number.html" title="enum ron::value::Number">Number</a>;</code></div></li><li><div class="item-name" id="reexport.Value"><code>pub use value::<a class="enum" href="value/enum.Value.html" title="enum ron::value::Value">Value</a>;</code></div></li></ul><h2 id="modules" class="section-header">Modules<a href="#modules" class="anchor">§</a></h2><ul class="item-table"><li><div class="item-name"><a class="mod" href="de/index.html" title="mod ron::de">de</a></div></li><li><div class="item-name"><a class="mod" href="error/index.html" title="mod ron::error">error</a></div></li><li><div class="item-name"><a class="mod" href="extensions/index.html" title="mod ron::extensions">extensions</a></div></li><li><div class="item-name"><a class="mod" href="options/index.html" title="mod ron::options">options</a></div><div class="desc docblock-short">Roundtrip serde Options module.</div></li><li><div class="item-name"><a class="mod" href="ser/index.html" title="mod ron::ser">ser</a></div></li><li><div class="item-name"><a class="mod" href="value/index.html" title="mod ron::value">value</a></div><div class="desc docblock-short">Value module.</div></li></ul></section></div></main></body></html> |