use std::io;
use libyaml_sys as sys;
use crate::{Emitter, EmitterError, Encoding, LineBreak};
pub struct EmitterBuilder<'a> {
emitter: Box<Emitter<'a>>,
}
impl<'a> EmitterBuilder<'a> {
pub fn new<W: io::Write + 'a>(writer: W) -> Result<Self, EmitterError> {
Emitter::new(writer).map(|emitter| Self { emitter })
}
pub fn finish(self) -> Box<Emitter<'a>> {
self.emitter
}
pub fn canonical(mut self, enable: bool) -> Self {
unsafe {
sys::yaml_emitter_set_canonical(
self.emitter.as_raw_ptr(),
enable as _,
)
}
self
}
pub fn encoding(mut self, encoding: Encoding) -> Self {
unsafe {
sys::yaml_emitter_set_encoding(
self.emitter.as_raw_ptr(),
encoding.into_raw(),
)
}
self
}
pub fn indent(mut self, indent: usize) -> Self {
unsafe {
sys::yaml_emitter_set_indent(
self.emitter.as_raw_ptr(),
indent as _,
)
}
self
}
pub fn line_break(mut self, line_break: LineBreak) -> Self {
unsafe {
sys::yaml_emitter_set_break(
self.emitter.as_raw_ptr(),
line_break.into_raw(),
)
}
self
}
pub fn line_width(mut self, width: usize) -> Self {
unsafe {
sys::yaml_emitter_set_width(
self.emitter.as_raw_ptr(),
width as _,
)
}
self
}
pub fn unicode(mut self, enable: bool) -> Self {
unsafe {
sys::yaml_emitter_set_unicode(
self.emitter.as_raw_ptr(),
enable as _,
)
}
self
}
}