valq 0.3.1

macros for querying semi-structured data with the JavaScript-like syntax
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
use valq::query_value;

macro_rules! test_is_some_of_expected_val {
    ($tests:expr) => {
        for (res, exp) in $tests {
            if let Some(act) = res {
                assert_eq!(act, &exp)
            }
            else {
                panic!("expect Some(...) but actually None")
            }
        }
    };
}

macro_rules! test_all_true_or_failed_idx {
    ($test_res:expr) => {
        if let Some(failed_idx) = $test_res.iter().position(|&r| !r) {
            panic!("test idx: {} failed", failed_idx)
        }
    };
}

mod json {
    use super::query_value;
    use serde_json::{json, Value};

    fn make_sample_json() -> Value {
        json!({
            "str": "s",
            "nums": {
                "u64": 123,
                "i64": -123,
                "f64": 1.23,
            },
            "bool": true,
            "null": null,
            "obj": {
                "inner": "value",
                "more": "item"
            },
            "arr": [
                "first",
                42,
                { "hidden": "tale" },
                [0]
            ],
            "num_arr": [0, 1, 2],
            "1st": "prop starts with digit!"
        })
    }

    #[test]
    fn test_query_with_dot_syntax() {
        let j = make_sample_json();

        let tests = [
            (query_value!(j.str), json!("s")),
            (query_value!(j.nums.u64), json!(123)),
            (query_value!(j.nums.i64), json!(-123)),
            (query_value!(j.nums.f64), json!(1.23)),
            (query_value!(j.bool), json!(true)),
            (query_value!(j.null), json!(null)),
            (
                query_value!(j.obj),
                json!({"inner": "value", "more": "item"}),
            ),
            (query_value!(j.obj.inner), json!("value")),
            (
                query_value!(j.arr),
                json!(["first", 42, {"hidden": "tale"}, [0]]),
            ),
            (query_value!(j["1st"]), json!("prop starts with digit!")),
        ];

        test_is_some_of_expected_val!(tests);
    }

    #[test]
    fn test_query_with_bracket_syntax() {
        let j = make_sample_json();

        let tests = [
            (query_value!(j["str"]), json!("s")),
            (query_value!(j["nums"]["u64"]), json!(123)),
            (query_value!(j["nums"].i64), json!(-123)), // mixed query
            (query_value!(j["1st"]), json!("prop starts with digit!")),
        ];

        test_is_some_of_expected_val!(tests);
    }

    #[test]
    fn test_indexing_array() {
        let j = make_sample_json();
        let tests = [
            (query_value!(j.arr[0]), json!("first")),
            (query_value!(j.arr[1]), json!(42)),
            (query_value!(j.arr[2].hidden), json!("tale")), // more complex query!
            (query_value!(j.arr[3][0]), json!(0)),          // successive indexing
        ];

        test_is_some_of_expected_val!(tests);
    }

    #[test]
    fn test_query_mut() {
        let mut j = make_sample_json();

        // rewriting value of prop
        {
            let obj_inner = query_value!(mut j.obj.inner).unwrap();
            *obj_inner = json!("just woke up!");
        }
        assert_eq!(
            query_value!(j.obj),
            Some(&json!({"inner": "just woke up!", "more": "item"}))
        );

        // get inner object as Map, then add new prop via insert()
        {
            let obj = query_value!(mut j.obj -> object).unwrap();
            obj.insert("new_prop".to_string(), json!("yeah"));
        }
        assert_eq!(query_value!(j.obj.new_prop -> str), Some("yeah"));

        // get inner array as Vec, then append new value via push()
        {
            let arr = query_value!(mut j.arr -> array).unwrap();
            arr.push(json!("appended!"));
        }
        assert_eq!(query_value!(j.arr[4] -> str), Some("appended!"));
    }

    #[test]
    fn test_query_with_ref_value() {
        let j = make_sample_json();
        let j_ref = &j;

        let tests = [
            (query_value!(j_ref.str), json!("s")),
            (query_value!(j_ref.nums.u64), json!(123)),
            (query_value!(j_ref.obj.inner), json!("value")),
        ];

        test_is_some_of_expected_val!(tests);
    }

    #[test]
    fn test_query_with_refmut_value() {
        let mut j = make_sample_json();
        let mut j_ref = &mut j;

        assert_eq!(
            query_value!(mut j_ref.obj.inner).unwrap(),
            &mut json!("value")
        );
    }

    #[test]
    fn test_query_and_cast() {
        let j = make_sample_json();

        let tests = [
            query_value!(j.str -> str) == Some("s"),
            query_value!(j.nums.u64 -> u64) == Some(123),
            query_value!(j.nums.i64 -> i64) == Some(-123),
            query_value!(j.nums.f64 -> f64) == Some(1.23),
            query_value!(j.bool -> bool) == Some(true),
            query_value!(j.null -> null) == Some(()),
            query_value!(j.obj -> object).unwrap().get("inner").unwrap() == "value",
            query_value!(j.arr -> array).unwrap()
                == &vec![
                    json!("first"),
                    json!(42),
                    json!({"hidden": "tale"}),
                    json!([0]),
                ],
        ];

        test_all_true_or_failed_idx!(tests);
    }

    #[test]
    fn test_query_and_deserialize() {
        use serde::Deserialize;

        let j = make_sample_json();

        let tests = [
            query_value!(j.str >> (String)) == Some("s".into()),
            query_value!(j.str >> (std::string::String)) == Some("s".into()),
            query_value!(j.str >> String) == Some("s".into()), // parens around type name can be omitted if single identifier
            query_value!(j.nums.u64 >> u8) == Some(123u8),
            query_value!(j.nums.i64 >> i8) == Some(-123i8),
            query_value!(j.nums.i64 >> u8) == None, // fails since can't deserialize negative value into u8
            query_value!(j.nums.f64 >> f32) == Some(1.23f32),
            query_value!(j.null >> (())) == Some(()),
        ];

        test_all_true_or_failed_idx!(tests);
    }

    #[test]
    fn test_deserialize_into_custom_struct() {
        use serde::Deserialize;

        #[derive(Debug, PartialEq, Deserialize)]
        struct Person {
            name: String,
            age: u8,
        }

        let j = json!({ "author": {"name": "jiftechnify", "age": 31 } });
        assert_eq!(
            query_value!(j.author >> Person),
            Some(Person {
                name: "jiftechnify".into(),
                age: 31u8,
            }),
        );
    }

    #[test]
    fn test_query_with_unwrapping() {
        let j = make_sample_json();

        let default_str = &json!("default");

        // basic query with ??
        assert_eq!(query_value!(j.str ?? default_str), &json!("s"));
        assert_eq!(query_value!(j.unknown ?? default_str), &json!("default"));

        // `?? default`
        assert_eq!(query_value!(j.nums.u64 -> u64 ?? default), 123u64);
        assert_eq!(query_value!(j.unknown -> u64 ?? default), 0u64); // u64::default()
        assert_eq!(query_value!(j.unknown -> str ?? default), ""); // &str::default()

        // with casting (->)
        assert_eq!(query_value!(j.str -> str ?? "default"), "s");
        assert_eq!(query_value!(j.nums.u64 -> u64 ?? 999), 123);
        assert_eq!(
            query_value!(j.nums.u64 -> str ?? "not a string"),
            "not a string"
        ); // type mismatch
        assert_eq!(query_value!(j.unknown -> str ?? "default"), "default");
        assert_eq!(query_value!(j.unknown -> str ?? default), ""); // &str::default()

        // with deserialization (>>)
        use serde::Deserialize;

        #[derive(Debug, PartialEq, Deserialize, Default)]
        struct Nums {
            u64: u64,
            i64: i64,
            f64: f64,
        }

        let expected_nums = Nums {
            u64: 123,
            i64: -123,
            f64: 1.23,
        };

        assert_eq!(query_value!(j.nums >> Nums ?? default), expected_nums);
        assert_eq!(
            query_value!(j.unknown >> Nums ?? Nums { u64: 999, i64: -999, f64: 9.99 }),
            Nums {
                u64: 999,
                i64: -999,
                f64: 9.99
            }
        );
        assert_eq!(
            query_value!(j.unknown >> Nums ?? default),
            Nums {
                u64: 0,
                i64: 0,
                f64: 0.0,
            }
        );

        assert_eq!(
            query_value!(j.num_arr >> (Vec<u8>) ?? default),
            vec![0, 1, 2]
        );
        assert_eq!(
            query_value!(j.arr >> (Vec<u8>) ?? default),
            Vec::<u8>::new()
        );
        assert_eq!(query_value!(j.arr >> (Vec<u8>) ?? vec![42]), vec![42]);
    }

    #[test]
    fn test_deserialize_into_vec() {
        use serde::Deserialize;

        let j = make_sample_json();

        let tests = [
            query_value!(j.num_arr >> (Vec<u8>)) == Some(vec![0, 1, 2]),
            query_value!(j.num_arr >> (Vec<u8>) ?? default) == vec![0, 1, 2],
            query_value!(j.arr >> (Vec<u8>)) == None,
            query_value!(j.arr >> (Vec<u8>) ?? default) == Vec::<u8>::new(),
            query_value!(j.arr >> (Vec<u8>) ?? vec![42]) == vec![42],
        ];
        test_all_true_or_failed_idx!(tests);
    }

    #[test]
    fn test_deserialize_into_hash_map() {
        use serde::Deserialize;
        use serde_json::{json, Value};
        use std::collections::HashMap;

        let j = make_sample_json();

        let exp_json: HashMap<String, Value> = HashMap::from([
            ("inner".into(), json!("value")),
            ("more".into(), json!("item")),
        ]);

        let exp_string: HashMap<String, String> = HashMap::from([
            ("inner".into(), "value".into()),
            ("more".into(), "item".into()),
        ]);

        let tests = [
            query_value!(j.obj >> (HashMap<String, Value>)) == Some(exp_json),
            query_value!(j.obj >> (HashMap<String, String>)) == Some(exp_string),
            query_value!(j.obj >> (HashMap<String, u8>)) == None,
        ];
        test_all_true_or_failed_idx!(tests);
    }

    #[test]
    fn test_query_fail() {
        let j = make_sample_json();

        let tests = [
            query_value!(j.unknown),   // non existent property
            query_value!(j.nums.i128), // non existent property of nested object
            query_value!(j.obj[0]),    // indexing against non-array value
            query_value!(j.arr[100]),  // indexing out of bound
        ]
        .iter()
        .map(|res| res.is_none())
        .collect::<Vec<_>>();

        test_all_true_or_failed_idx!(tests);
    }

    #[test]
    fn test_query_fail_mut() {
        let mut j = make_sample_json();

        let tests = [
            { query_value!(mut j.unknown).is_none() },
            { query_value!(mut j.nums.i128).is_none() },
            { query_value!(mut j.obj[0]).is_none() },
            { query_value!(mut j.arr[100]).is_none() },
        ];

        test_all_true_or_failed_idx!(tests);
    }

    #[test]
    fn test_query_with_dynamic_indices() {
        let j = make_sample_json();

        // Dynamic string key
        let key = "str";
        assert_eq!(query_value!(j[key]), Some(&json!("s")));

        let obj_key = "obj";
        let inner_key = "inner";
        assert_eq!(query_value!(j[obj_key][inner_key]), Some(&json!("value")));

        // Dynamic integer index
        let index = 0;
        assert_eq!(query_value!(j.arr[index]), Some(&json!("first")));

        let arr_index = 1;
        assert_eq!(query_value!(j.arr[arr_index]), Some(&json!(42)));

        // Mix of static and dynamic
        let key2 = "nums";
        assert_eq!(query_value!(j[key2].u64), Some(&json!(123)));

        // Dynamic expression
        let base_index = 1;
        assert_eq!(
            query_value!(j.arr[base_index + 1].hidden),
            Some(&json!("tale"))
        );

        // With casting (->)
        assert_eq!(query_value!(j[key] -> str), Some("s"));
        assert_eq!(query_value!(j.arr[index] -> str), Some("first"));

        // With unwrapping operator
        let missing_key = "missing";
        let fallback = json!("fallback");
        assert_eq!(
            query_value!(j[missing_key]?? & fallback),
            &json!("fallback")
        );

        let out_of_bounds = 999;
        let oob_val = json!("oob");
        assert_eq!(
            query_value!(j.arr[out_of_bounds]?? & oob_val),
            &json!("oob")
        );
    }

    #[test]
    fn test_query_with_dynamic_indices_mut() {
        let mut j = make_sample_json();

        // Dynamic string key (mut)
        let key = "str";
        {
            let val = query_value!(mut j[key]).unwrap();
            *val = json!("modified");
        }
        assert_eq!(query_value!(j.str), Some(&json!("modified")));

        // Dynamic integer index (mut)
        let index = 1;
        {
            let val = query_value!(mut j.arr[index]).unwrap();
            *val = json!(100);
        }
        assert_eq!(query_value!(j.arr[1]), Some(&json!(100)));

        // With casting (mut)
        let obj_key = "obj";
        let dynamic_key = "dynamic_key";
        {
            let obj = query_value!(mut j[obj_key] -> object).unwrap();
            obj.insert("dynamic_key".to_string(), json!("added"));
        }
        assert_eq!(query_value!(j.obj[dynamic_key]), Some(&json!("added")));
    }

    #[test]
    fn test_query_complex_expressions() {
        use serde::Deserialize;

        fn gen_value() -> serde_json::Value {
            json!({ "x": 1 })
        }

        let tuple = (json!({ "x": 1 }),);

        struct S {
            value: serde_json::Value,
        }
        impl S {
            fn new() -> Self {
                Self {
                    value: json!({ "x": 1 }),
                }
            }
            fn gen_value(&self) -> serde_json::Value {
                json!({ "x": 1 })
            }
        }
        let s = S::new();

        let v = vec![json!({ "x": 1 })];

        let tests = [
            // querying immediate value
            query_value!((json!({ "x": 1 })).x) == Some(&json!(1)),
            query_value!((json!({ "x": 1 })).y ?? default) == &json!(null),
            query_value!((json!({ "x": 1 })).x -> u64) == Some(1u64),
            query_value!((json!({ "x": 1 })).x -> str ?? default) == "",
            query_value!((json!({ "x": 1 })).x -> str ?? "not str") == "not str",
            query_value!((json!({ "x": 1 })).x >> u8) == Some(1u8),
            query_value!((json!({ "x": 1 })).x >> String ?? default) == "".to_string(),
            query_value!((json!({ "x": 1 })).x >> String ?? "deser failed".to_string())
                == "deser failed".to_string(),
            // querying immediate value (mut)
            query_value!(mut (json!({ "x": 1 })).x) == Some(&mut json!(1)),
            query_value!(mut (json!({ "x": 1 })).x >> u8) == Some(1u8),
            query_value!(mut (json!({ "x": 1 })).x >> String ?? "deser failed".to_string())
                == "deser failed".to_string(),
            // querying return value of function
            query_value!((gen_value()).x) == Some(&json!(1)),
            query_value!((gen_value()).x -> u64) == Some(1u64),
            query_value!((gen_value()).x -> str ?? "not str") == "not str",
            // querying element of tuple
            query_value!((tuple.0).x) == Some(&json!(1)),
            query_value!((tuple.0).x -> u64) == Some(1u64),
            query_value!((tuple.0).x -> str ?? "not str") == "not str",
            // querying field of struct
            query_value!((s.value).x) == Some(&json!(1)),
            query_value!((s.value).x -> u64) == Some(1u64),
            query_value!((s.value).x -> str ?? "not str") == "not str",
            // querying return value of method
            query_value!((s.gen_value()).x) == Some(&json!(1)),
            query_value!((s.gen_value()).x -> u64) == Some(1u64),
            query_value!((s.gen_value()).x -> str ?? "not str") == "not str",
            // querying indexed value
            query_value!((v[0]).x) == Some(&json!(1)),
            query_value!((v[0]).x -> u64) == Some(1u64),
            query_value!((v[0]).x -> str ?? "not str") == "not str",
        ];
        test_all_true_or_failed_idx!(tests);
    }
}

mod yaml {
    use super::query_value;
    use serde_yaml::{from_str, Mapping, Sequence, Value};

    fn make_sample_yaml() -> Value {
        let yaml_str = include_str!("../res/sample.yaml");
        from_str(yaml_str).unwrap()
    }

    fn sample_mapping() -> Mapping {
        Mapping::from_iter([
            (
                Value::String("first".to_string()),
                Value::String("zzz".to_string()),
            ),
            (
                Value::String("second".to_string()),
                Value::String("yyy".to_string()),
            ),
        ])
    }
    fn sample_map_in_seq() -> Mapping {
        Mapping::from_iter([(
            Value::String("hidden".to_string()),
            Value::String("tale".to_string()),
        )])
    }
    fn sample_sequence() -> Sequence {
        Sequence::from_iter(vec![
            Value::String("first".to_string()),
            Value::Number(42.into()),
            Value::Mapping(sample_map_in_seq()),
        ])
    }

    #[test]
    fn test_query() {
        let y = make_sample_yaml();

        let tests = [
            (query_value!(y.str), Value::String("s".to_string())),
            (query_value!(y.num), Value::Number(123.into())),
            (query_value!(y.map), Value::Mapping(sample_mapping())),
            (query_value!(y.map.second), Value::String("yyy".to_string())),
            (query_value!(y.seq), Value::Sequence(sample_sequence())),
            (query_value!(y.seq[0]), Value::String("first".to_string())),
            (query_value!(y.seq[2]), Value::Mapping(sample_map_in_seq())),
        ];
        test_is_some_of_expected_val!(tests);
    }

    #[test]
    fn test_query_and_cast() {
        let y = make_sample_yaml();

        let tests = [
            query_value!(y.str -> str) == Some("s"),
            query_value!(y.num -> u64) == Some(123),
            query_value!(y.map -> mapping).unwrap().len() == 2,
            query_value!(y.seq -> sequence).unwrap()
                == &vec![
                    Value::String("first".to_string()),
                    Value::Number(42.into()),
                    Value::Mapping(sample_map_in_seq()),
                ],
        ];

        test_all_true_or_failed_idx!(tests);
    }

    #[test]
    fn test_query_and_deserialize() {
        use serde::Deserialize;

        #[derive(Debug, PartialEq, Deserialize)]
        struct Person {
            name: String,
            age: u8,
        }

        let y = make_sample_yaml();
        assert_eq!(
            query_value!(y.author >> Person),
            Some(Person {
                name: "jiftechnify".into(),
                age: 31u8,
            }),
        );
    }
}

mod toml {
    use super::query_value;
    use toml::{
        from_str,
        value::{Array, Table},
        Value,
    };

    fn make_sample_toml() -> Value {
        let toml_str = include_str!("../res/sample.toml");
        from_str(toml_str).unwrap()
    }
    fn sample_table() -> Table {
        Table::from_iter([
            ("first".to_string(), Value::String("zzz".to_string())),
            ("second".to_string(), Value::String("yyy".to_string())),
        ])
    }
    fn sample_array() -> Array {
        vec!["first", "second", "third"]
            .into_iter()
            .map(|e| Value::String(e.to_string()))
            .collect()
    }
    fn sample_arr_of_tables() -> Array {
        let t1 = Table::from_iter([("hidden".to_string(), Value::String("tale".to_string()))]);
        let t2 = Table::from_iter([
            ("hoge".to_string(), Value::Integer(1)),
            ("fuga".to_string(), Value::Integer(2)),
        ]);
        let t3 = Table::from_iter([(
            "inner_arr".to_string(),
            Value::Array(vec![
                Value::Integer(1),
                Value::Integer(2),
                Value::Integer(3),
            ]),
        )]);

        vec![t1, t2, t3].into_iter().map(Value::Table).collect()
    }

    #[test]
    fn test_query() {
        let t = make_sample_toml();

        let tests = [
            (query_value!(t.str), Value::String("s".to_string())),
            (query_value!(t.int), Value::Integer(123)),
            (query_value!(t.float), Value::Float(1.23)),
            (query_value!(t.table), Value::Table(sample_table())),
            (
                query_value!(t.table.second),
                Value::String("yyy".to_string()),
            ),
            (query_value!(t.arr), Value::Array(sample_array())),
            (query_value!(t.arr[2]), Value::String("third".to_string())),
            (
                query_value!(t.arr_of_tables),
                Value::Array(sample_arr_of_tables()),
            ),
            (
                query_value!(t.arr_of_tables[0].hidden),
                Value::String("tale".to_string()),
            ),
            (
                query_value!(t.arr_of_tables[2].inner_arr[0]),
                Value::Integer(1),
            ),
        ];
        test_is_some_of_expected_val!(tests);
    }

    #[test]
    fn test_query_and_cast() {
        let t = make_sample_toml();

        let tests = [
            query_value!(t.str -> str) == Some("s"),
            query_value!(t.int -> integer) == Some(123),
            query_value!(t.float -> float) == Some(1.23),
            query_value!(t.date -> datetime).unwrap().to_string() == "2021-12-18T12:15:12+09:00",
            query_value!(t.table -> table).unwrap().len() == 2,
            query_value!(t.arr -> array).unwrap()
                == &vec!["first", "second", "third"]
                    .into_iter()
                    .map(|v| Value::String(v.to_string()))
                    .collect::<Vec<_>>(),
            query_value!(t.arr_of_tables -> array).unwrap().len() == 3,
        ];

        test_all_true_or_failed_idx!(tests);
    }

    #[test]
    fn test_query_and_deserialize() {
        use serde::Deserialize;

        #[derive(Debug, PartialEq, Deserialize)]
        struct Person {
            name: String,
            age: u8,
        }

        let t = make_sample_toml();
        assert_eq!(
            query_value!(t.author >> Person),
            Some(Person {
                name: "jiftechnify".into(),
                age: 31u8,
            }),
        );
    }
}