1
0
mirror of https://github.com/sharkdp/bat.git synced 2024-10-05 18:31:06 +01:00
bat/examples/yaml.rs

37 lines
913 B
Rust
Raw Normal View History

2020-04-22 20:42:09 +01:00
/// A program that serializes a Rust structure to YAML and pretty-prints the result
2020-05-16 23:16:51 +01:00
use bat::{Input, PrettyPrinter};
2020-04-22 20:42:09 +01:00
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![],
}],
};
2023-10-01 18:44:10 +01:00
let mut bytes = Vec::with_capacity(128);
serde_yaml::to_writer(&mut bytes, &person).unwrap();
2020-04-22 20:42:09 +01:00
PrettyPrinter::new()
.language("yaml")
.line_numbers(true)
2020-04-22 21:41:25 +01:00
.grid(true)
.header(true)
2020-05-16 23:16:51 +01:00
.input(Input::from_bytes(&bytes).name("person.yaml").kind("File"))
2020-04-22 20:42:09 +01:00
.print()
.unwrap();
}