File: value_derive.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 (33 lines) | stat: -rw-r--r-- 586 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
#![cfg(feature="sval_derive")]
/*!
Values are Rust structures that represent a single instance of some datatype.

This example implements the `Value` trait automatically using Rust's `#[derive]` attribute.
*/

#[macro_use]
extern crate sval_derive;

pub mod stream;

#[derive(Value)]
pub struct MyData<'a> {
    id: u64,
    title: &'a str,
}

fn main() -> sval::Result {
    stream(MyData {
        id: 547,
        title: "Some data",
    })?;

    Ok(())
}

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

    Ok(())
}