Skip to content

Commit

Permalink
add example using the Options method
Browse files Browse the repository at this point in the history
  • Loading branch information
sylv256 committed Jan 4, 2024
1 parent 8605b97 commit 5f29b8c
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions docs/extensions.md
Original file line number Diff line number Diff line change
Expand Up @@ -138,3 +138,16 @@ Foo(
```

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).

Here is an example of how to enable `explicit_struct_names` using this method:
```rust
use ron::extensions::Extensions;
use ron::options::Options;

// Setup the options
let options = Options::default().with_default_extension(Extensions::EXPLICIT_STRUCT_NAMES);
// Retrieve the contents of the file
let file_contents: &str = /* ... */;
// Parse the file's contents
let foo: Foo = options.from_str(file_contents)?;
```

0 comments on commit 5f29b8c

Please sign in to comment.