Struct yaml_rust2::emitter::YamlEmitter
source · pub struct YamlEmitter<'a> { /* private fields */ }
Expand description
The YAML serializer.
let input_string = "a: b\nc: d";
let yaml = YamlLoader::load_from_str(input_string).unwrap();
let mut output = String::new();
YamlEmitter::new(&mut output).dump(&yaml[0]).unwrap();
assert_eq!(output, r#"---
a: b
c: d"#);
Implementations§
source§impl<'a> YamlEmitter<'a>
impl<'a> YamlEmitter<'a>
sourcepub fn new(writer: &'a mut dyn Write) -> YamlEmitter<'_>
pub fn new(writer: &'a mut dyn Write) -> YamlEmitter<'_>
Create a new emitter serializing into writer
.
sourcepub fn is_compact(&self) -> bool
pub fn is_compact(&self) -> bool
Determine if this emitter is using ‘compact inline notation’.
sourcepub fn multiline_strings(&mut self, multiline_strings: bool)
pub fn multiline_strings(&mut self, multiline_strings: bool)
Render strings containing multiple lines in literal style.
§Examples
use yaml_rust2::{Yaml, YamlEmitter, YamlLoader};
let input = r#"{foo: "bar!\nbar!", baz: 42}"#;
let parsed = YamlLoader::load_from_str(input).unwrap();
eprintln!("{:?}", parsed);
let mut output = String::new();
let mut emitter = YamlEmitter::new(&mut output);
emitter.multiline_strings(true);
emitter.dump(&parsed[0]).unwrap();
assert_eq!(output.as_str(), "\
---
foo: |
bar!
bar!
baz: 42");
sourcepub fn is_multiline_strings(&self) -> bool
pub fn is_multiline_strings(&self) -> bool
Determine if this emitter will emit multiline strings when appropriate.
sourcepub fn dump(&mut self, doc: &Yaml) -> EmitResult
pub fn dump(&mut self, doc: &Yaml) -> EmitResult
Auto Trait Implementations§
impl<'a> Freeze for YamlEmitter<'a>
impl<'a> !RefUnwindSafe for YamlEmitter<'a>
impl<'a> !Send for YamlEmitter<'a>
impl<'a> !Sync for YamlEmitter<'a>
impl<'a> Unpin for YamlEmitter<'a>
impl<'a> !UnwindSafe for YamlEmitter<'a>
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more