File: stream_simple.rs

package info (click to toggle)
rust-sval 2.6.1-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 304 kB
  • sloc: makefile: 2
file content (47 lines) | stat: -rw-r--r-- 904 bytes parent folder | download
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
/*!
Streams have a simple core data-model that consists of:

- Nulls: the lack of any meaningful value.
- Booleans: `true` and `false`.
- Signed integers.
- Binary floating point numbers.
- Text strings.
- Sequences of values.

This example implements a simple stream that writes directly to stdout.
*/

pub mod stream;

fn main() -> sval::Result {
    stream(42)?;
    stream(true)?;

    stream(Some(42))?;
    stream(None::<i32>)?;

    #[cfg(feature = "alloc")]
    stream({
        use std::collections::BTreeMap;

        let mut map = BTreeMap::new();

        map.insert("a", 1);
        map.insert("b", 2);
        map.insert("c", 3);

        map
    })?;

    #[cfg(feature = "alloc")]
    stream(vec![vec!["Hello", "world"], vec!["Hello", "world"]])?;

    Ok(())
}

fn stream(v: impl sval::Value) -> sval::Result {
    v.stream(&mut stream::simple::MyStream)?;
    println!();

    Ok(())
}