Struct yaml2json_rs::Yaml2Json [−][src]
pub struct Yaml2Json { /* fields omitted */ }
Expand description
Yaml2Json can convert individual YAML documents into JSON. Each instance can be configured to have different styles of output.
The JSON output can be returned as a string:
use yaml2json_rs::{Yaml2Json, Style}; let y2j = Yaml2Json::new(Style::COMPACT); let input = "hello: world"; let output = y2j.document_to_string(input).unwrap(); assert_eq!(output, r#"{"hello":"world"}"#);
Or, the JSON output can be sent to a writer:
use yaml2json_rs::{Yaml2Json, Style}; use std::io; let y2j = Yaml2Json::new(Style::COMPACT); let input = "hello: world"; let mut stdout = io::stdout(); y2j.document_to_writer(input, &mut stdout); // {"hello":"world"}
Implementations
new()
creates a new Yaml2Json
. It expects you to provide an output Style
.
use yaml2json_rs::{Yaml2Json, Style}; let y2j_pretty = Yaml2Json::new(Style::PRETTY); let y2j_compact = Yaml2Json::new(Style::COMPACT);
document_to_string()
takes a YAML document &str and converts it to a JSON String.
use yaml2json_rs::{Yaml2Json, Style}; let y2j = Yaml2Json::new(Style::COMPACT); let input = "hello: world"; let output = y2j.document_to_string(input).unwrap(); assert_eq!(output, r#"{"hello":"world"}"#);
pub fn document_to_writer<W: Write>(
&self,
document: &str,
w: &mut W
) -> Result<(), Yaml2JsonError>
pub fn document_to_writer<W: Write>(
&self,
document: &str,
w: &mut W
) -> Result<(), Yaml2JsonError>
document_to_writer()
takes a YAML document string, converts it to JSON and sends the output
to the provided writer.
use yaml2json_rs::{Yaml2Json, Style}; use std::io; let y2j = Yaml2Json::new(Style::COMPACT); let input = "hello: world"; let mut stdout = io::stdout(); y2j.document_to_writer(input, &mut stdout); // {"hello":"world"}
Auto Trait Implementations
impl RefUnwindSafe for Yaml2Json
impl UnwindSafe for Yaml2Json