1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
use std::io;
use crate::{Emitter, EmitterError, Encoding, LineBreak};
use crate::sys;
/// Builder for emitters.
pub struct EmitterBuilder<'a> {
emitter: Box<Emitter<'a>>,
}
impl<'a> EmitterBuilder<'a> {
/// Start building an emitter.
pub fn new<W: io::Write + 'a>(writer: W) -> Result<Self, EmitterError> {
Emitter::new(writer).map(|emitter| Self { emitter })
}
/// Finish building an emitter.
pub fn finish(self) -> Box<Emitter<'a>> {
self.emitter
}
/// Enable or disable canonical output.
pub fn canonical(mut self, enable: bool) -> Self {
unsafe {
sys::yaml_emitter_set_canonical(
self.emitter.as_raw_ptr(),
enable as _,
)
}
self
}
/// Set encoding.
pub fn encoding(mut self, encoding: Encoding) -> Self {
unsafe {
sys::yaml_emitter_set_encoding(
self.emitter.as_raw_ptr(),
encoding.into_raw(),
)
}
self
}
/// Set indentation increment.
pub fn indent(mut self, indent: usize) -> Self {
unsafe {
sys::yaml_emitter_set_indent(
self.emitter.as_raw_ptr(),
indent as _,
)
}
self
}
/// Set line break encoding.
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
}
/// Set preferred line width.
pub fn line_width(mut self, width: usize) -> Self {
unsafe {
sys::yaml_emitter_set_width(
self.emitter.as_raw_ptr(),
width as _,
)
}
self
}
/// Enable or disable unescaped non-ASCII characters in output.
pub fn unicode(mut self, enable: bool) -> Self {
unsafe {
sys::yaml_emitter_set_unicode(
self.emitter.as_raw_ptr(),
enable as _,
)
}
self
}
}