diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-28 14:29:10 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-28 14:29:10 +0000 |
commit | 2aa4a82499d4becd2284cdb482213d541b8804dd (patch) | |
tree | b80bf8bf13c3766139fbacc530efd0dd9d54394c /third_party/rust/ron/docs/extensions.md | |
parent | Initial commit. (diff) | |
download | firefox-2aa4a82499d4becd2284cdb482213d541b8804dd.tar.xz firefox-2aa4a82499d4becd2284cdb482213d541b8804dd.zip |
Adding upstream version 86.0.1.upstream/86.0.1upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'third_party/rust/ron/docs/extensions.md')
-rw-r--r-- | third_party/rust/ron/docs/extensions.md | 67 |
1 files changed, 67 insertions, 0 deletions
diff --git a/third_party/rust/ron/docs/extensions.md b/third_party/rust/ron/docs/extensions.md new file mode 100644 index 0000000000..ae648d778a --- /dev/null +++ b/third_party/rust/ron/docs/extensions.md @@ -0,0 +1,67 @@ +## RON extensions + +RON has extensions that can be enabled by adding the following attribute at the top of your RON document: + +`#![enable(...)]` + +# unwrap_newtypes + +You can add this extension by adding the following attribute at the top of your RON document: + +`#![enable(unwrap_newtypes)]` + +This feature enables RON to automatically unwrap simple tuples. + +```rust +struct NewType(u32); +struct Object { + pub new_type: NewType, +} +``` + +Without `unwrap_newtypes`, because the value `5` can not be saved into `NewType(u32)`, your RON document would look like this: + +``` ron +( + new_type: (5), +) +``` + +With the `unwrap_newtypes` extension, this coercion is done automatically. So `5` will be interpreted as `(5)`. + +``` ron +#![enable(unwrap_newtypes)] +( + new_type: 5, +) +``` + +# implicit_some + +You can add this extension by adding the following attribute at the top of your RON document: + +`#![enable(implicit_some)]` + +This feature enables RON to automatically convert any value to `Some(value)` if the deserialized struct requires it. + +```rust +struct Object { + pub value: Option<u32>, +} +``` + +Without this feature, you would have to write this RON document. + +```ron +( + value: Some(5), +) +``` + +Enabling the feature would automatically infer `Some(x)` if `x` is given. In this case, RON automatically casts this `5` into a `Some(5)`. + +```ron +( + value: 5, +) +``` |