Skip to content

Commit

Permalink
add documentation, improve comments
Browse files Browse the repository at this point in the history
  • Loading branch information
sylv256 committed Jan 4, 2024
1 parent cf7710e commit 8605b97
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 3 deletions.
24 changes: 24 additions & 0 deletions docs/extensions.md
Original file line number Diff line number Diff line change
Expand Up @@ -114,3 +114,27 @@ With the `unwrap_variant_newtypes` extension, the first structural layer inside
```

Note that when the `unwrap_variant_newtypes` extension is enabled, the first layer inside a newtype variant will **always** be unwrapped, i.e. it is no longer possible to write `A(Inner(a: 4, b: true))` or `A((a: 4, b: true))`.

# explicit_struct_names
This extension requires that all structs have names attached to them. For example, the following deserializes perfectly fine:
```ron
Foo(
bar: Bar(42),
)
```

However, with the `explicit_struct_names` extension enabled, the following will throw an `ExpectedStructName` error:
```ron
(
bar: Bar(42),
)
```

Similarly, the following will throw the same error:
```ron
Foo(
bar: (42),
)
```

Note that if what you are parsing is spread across many files, you would likely use `Options::with_default_extension` to enable `Extensions::EXPLICIT_STRUCT_NAMES` before the parsing stage. This is because prepending `#![enable(explicit_struct_names)]` to the contents of every file you parse would violate DRY (Don't Repeat Yourself).
6 changes: 3 additions & 3 deletions tests/522_explicit_struct_names.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ fn explicit_struct_names() {
let options = Options::default()
.with_default_extension(Extensions::EXPLICIT_STRUCT_NAMES);

// phase 1
// phase 1 (regular structs)
let content = r#"(
id: Id(3),
)"#;
Expand All @@ -28,7 +28,7 @@ fn explicit_struct_names() {
err => panic!("{INCORRECT_ERROR_MESSAGE} \"{err}\""),
}

// phase 2
// phase 2 (newtype structs)
let content = r#"Foo(
id: (3),
)"#;
Expand All @@ -38,6 +38,6 @@ fn explicit_struct_names() {
err => panic!("{INCORRECT_ERROR_MESSAGE} \"{err}\""),
}

// phase 3 (use content from phase 2)
// phase 3 (test without this extension)
let _foo = from_str::<Foo>(content).unwrap();
}

0 comments on commit 8605b97

Please sign in to comment.