Skip to content

Commit

Permalink
Fix and improve usage examples
Browse files Browse the repository at this point in the history
  • Loading branch information
Marcono1234 committed Dec 30, 2023
1 parent b9cf832 commit 73aab64
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 deletions.
10 changes: 6 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@ Any feedback is appreciated!
See [`SimpleJsonReader`](https://docs.rs/struson/latest/struson/reader/simple/struct.SimpleJsonReader.html).

```rust
# use struson::reader::simple::*;
use struson::reader::simple::*;

// In this example JSON data comes from a string;
// normally it would come from a file or a network connection
let json_reader = SimpleJsonReader::new(r#"["a", "short", "example"]"#.as_bytes());
Expand All @@ -66,15 +67,15 @@ json_reader.next_array_items(|item_reader| {
Ok(())
})?;
assert_eq!(words, vec!["a", "short", "example"]);
# Ok::<(), Box<dyn std::error::Error>>(())
```

#### Writing

See [`SimpleJsonWriter`](https://docs.rs/struson/latest/struson/writer/simple/struct.SimpleJsonWriter.html).

```rust
# use struson::writer::simple::*;
use struson::writer::simple::*;

// In this example JSON bytes are stored in a Vec;
// normally they would be written to a file or network connection
let mut writer = Vec::<u8>::new();
Expand All @@ -87,7 +88,6 @@ json_writer.object_value(|object_writer| {

let json = String::from_utf8(writer)?;
assert_eq!(json, r#"{"a":1,"b":true}"#);
# Ok::<(), Box<dyn std::error::Error>>(())
```

### Advanced API
Expand All @@ -98,6 +98,7 @@ See [`JsonStreamReader`](https://docs.rs/struson/latest/struson/reader/struct.Js

```rust
use struson::reader::*;

// In this example JSON data comes from a string;
// normally it would come from a file or a network connection
let json = r#"{"a": [1, true]}"#;
Expand All @@ -122,6 +123,7 @@ See [`JsonStreamWriter`](https://docs.rs/struson/latest/struson/writer/struct.Js

```rust
use struson::writer::*;

// In this example JSON bytes are stored in a Vec;
// normally they would be written to a file or network connection
let mut writer = Vec::<u8>::new();
Expand Down
12 changes: 8 additions & 4 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@
//! ```
//! # #[cfg(feature = "experimental")]
//! # {
//! # use struson::reader::simple::*;
//! use struson::reader::simple::*;
//!
//! // In this example JSON data comes from a string;
//! // normally it would come from a file or a network connection
//! let json_reader = SimpleJsonReader::new(r#"["a", "short", "example"]"#.as_bytes());
Expand All @@ -74,7 +75,8 @@
//! ```
//! # #[cfg(feature = "experimental")]
//! # {
//! # use struson::writer::simple::*;
//! use struson::writer::simple::*;
//!
//! // In this example JSON bytes are stored in a Vec;
//! // normally they would be written to a file or network connection
//! let mut writer = Vec::<u8>::new();
Expand All @@ -97,7 +99,8 @@
//! See [`JsonStreamReader`](crate::reader::JsonStreamReader).
//!
//! ```
//! # use struson::reader::*;
//! use struson::reader::*;
//!
//! // In this example JSON data comes from a string;
//! // normally it would come from a file or a network connection
//! let json = r#"{"a": [1, true]}"#;
Expand All @@ -121,7 +124,8 @@
//! See [`JsonStreamWriter`](crate::writer::JsonStreamWriter).
//!
//! ```
//! # use struson::writer::*;
//! use struson::writer::*;
//!
//! // In this example JSON bytes are stored in a Vec;
//! // normally they would be written to a file or network connection
//! let mut writer = Vec::<u8>::new();
Expand Down

0 comments on commit 73aab64

Please sign in to comment.