Skip to content

Commit

Permalink
Adds changes for rust code blocks
Browse files Browse the repository at this point in the history
  • Loading branch information
desaikd committed Nov 5, 2024
1 parent bf00e49 commit b72b043
Showing 1 changed file with 20 additions and 18 deletions.
38 changes: 20 additions & 18 deletions src/bin/ion/commands/generate/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -343,21 +343,21 @@ types defined within the outer types.
Generated type has a `readFrom` method which can be used to read Ion data using `Reader` and initialize the generated
type with the given Ion data. *(Generated code here depends on `ion-rs` version `1.0.0-rc.2`)*

```rust
let mut reader: Reader = ReaderBuilder::new().build(ION_DATA) ?;
reader.next() ?;
let foo: Foo = Foo::read_from( & mut reader) ?;
```
let mut reader: Reader = ReaderBuilder::new().build(ION_DATA)?;
reader.next()?;
let foo: Foo = Foo::read_from(&mut reader)?;
```

### Write a generated type to an `Writer`

Generated type has a `writeTo` method which can be used to write the type as Ion using `Writer` . *(Generated code here
depends on `ion-rs` version `1.0.0-rc.2`)*

```rust
let mut text_writer = TextWriterBuilder::default ().build( & mut buffer) ?;
foo.write_to( & mut text_writer) ?;
text_writer.flush() ?;
```
let mut text_writer = TextWriterBuilder::default().build(&mut buffer)?;
foo.write_to(&mut text_writer)?;
text_writer.flush()?;
```

## Appendix A – Built-in ISL types and corresponding generated types
Expand Down Expand Up @@ -403,18 +403,20 @@ the model as Ion data) are defined.*
**Ion Schema:**

```
type::{
// this will be used as the name of the generated class
name: person,
// currently code generation doesn't allow open ended types,
// so for defining a `type` constraint is required
type: struct,
fields:{
first_name: string,
last_name: string,
age: int,
}
// this will be used as the name of the generated class
name: person,
// currently code generation doesn't allow open ended types,
// so for defining a `type` constraint is required
type: struct,
fields:{
first_name: string,
last_name: string,
age: int,
}
}
```

**Generated Code in Java:**
Expand Down

0 comments on commit b72b043

Please sign in to comment.