1
use justjson::doc::{HeaplessDocument, Node};
2
use justjson::{ErrorKind, JsonString};
3

            
4
1
fn main() {
5
1
    // Using a heapless vec, we can parse directly to the stack.
6
1
    let doc: HeaplessDocument<'_, 3> =
7
1
        HeaplessDocument::from_json(r#"{"hello": "world"}"#).expect("invalid json");
8
1
    let mut nodes = doc.into_iter();
9
1
    assert_eq!(nodes.next(), Some(Node::Object { length: 1 }));
10
1
    assert_eq!(nodes.next(), Some(Node::String(JsonString::from("hello"))));
11
1
    assert_eq!(nodes.next(), Some(Node::String(JsonString::from("world"))));
12

            
13
    // When parsing a document too large for the heapless Vec, an error will be
14
    // returned instead of panicing.
15
1
    let error = HeaplessDocument::<3>::from_json("[1, 2, 3, 4]").expect_err("shouldn't have space");
16
1
    assert_eq!(error.kind(), &ErrorKind::PaylodTooLarge);
17
1
}
18

            
19
1
#[test]
20
1
fn runs() {
21
1
    main();
22
1
}