mirror of
https://github.com/sharkdp/bat.git
synced 2025-01-31 02:01:05 +00:00
Add YAML example
This commit is contained in:
parent
13f671b499
commit
5f826419d1
33
examples/yaml.rs
Normal file
33
examples/yaml.rs
Normal file
@ -0,0 +1,33 @@
|
||||
/// A program that serializes a Rust structure to YAML and pretty-prints the result
|
||||
use bat::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 bytes = serde_yaml::to_vec(&person).unwrap();
|
||||
PrettyPrinter::new()
|
||||
.language("yaml")
|
||||
.line_numbers(true)
|
||||
.input_from_bytes(&bytes)
|
||||
.print()
|
||||
.unwrap();
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user