mirror of
https://github.com/sharkdp/bat
synced 2024-11-27 06:10:20 +00:00
36 lines
913 B
Rust
36 lines
913 B
Rust
/// A program that serializes a Rust structure to YAML and pretty-prints the result
|
|
use bat::{Input, PrettyPrinter};
|
|
use serde::Serialize;
|
|
|
|
#[derive(Serialize)]
|
|
struct Person {
|
|
name: String,
|
|
height: f64,
|
|
adult: bool,
|
|
children: Vec<Person>,
|
|
}
|
|
|
|
fn main() {
|
|
let person = Person {
|
|
name: String::from("Anne Mustermann"),
|
|
height: 1.76f64,
|
|
adult: true,
|
|
children: vec![Person {
|
|
name: String::from("Max Mustermann"),
|
|
height: 1.32f64,
|
|
adult: false,
|
|
children: vec![],
|
|
}],
|
|
};
|
|
|
|
let mut bytes = Vec::with_capacity(128);
|
|
serde_yaml::to_writer(&mut bytes, &person).unwrap();
|
|
PrettyPrinter::new()
|
|
.language("yaml")
|
|
.line_numbers(true)
|
|
.grid(true)
|
|
.header(true)
|
|
.input(Input::from_bytes(&bytes).name("person.yaml").kind("File"))
|
|
.print()
|
|
.unwrap();
|
|
}
|