libyml/
yaml.rs

1use crate::libc;
2use core::ops::Deref;
3use core::ptr::{self, addr_of};
4
5pub(crate) use self::{
6    YamlEncodingT::*, YamlEventTypeT::*, YamlNodeTypeT::*,
7};
8pub use core::primitive::{
9    i64 as ptrdiff_t, u64 as size_t, u8 as yaml_char_t,
10};
11
12/// The version directive data.
13#[derive(Copy, Clone, Debug, Default)]
14#[repr(C)]
15#[non_exhaustive]
16pub struct YamlVersionDirectiveT {
17    /// The major version number.
18    pub major: libc::c_int,
19    /// The minor version number.
20    pub minor: libc::c_int,
21}
22
23impl YamlVersionDirectiveT {
24    /// Constructor for `YamlVersionDirectiveT`.
25    pub fn new(major: libc::c_int, minor: libc::c_int) -> Self {
26        YamlVersionDirectiveT {
27            major,
28            minor,
29            // Initialize any future fields with their default values
30        }
31    }
32}
33
34/// The tag directive data.
35#[derive(Copy, Clone, Debug)]
36#[repr(C)]
37#[non_exhaustive]
38pub struct YamlTagDirectiveT {
39    /// The tag handle.
40    pub handle: *mut yaml_char_t,
41    /// The tag prefix.
42    pub prefix: *mut yaml_char_t,
43}
44
45/// The stream encoding.
46#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Debug)]
47#[repr(u32)]
48#[non_exhaustive]
49pub enum YamlEncodingT {
50    /// Let the parser choose the encoding.
51    YamlAnyEncoding = 0,
52    /// The default UTF-8 encoding.
53    YamlUtf8Encoding = 1,
54    /// The UTF-16-LE encoding with BOM.
55    YamlUtf16leEncoding = 2,
56    /// The UTF-16-BE encoding with BOM.
57    YamlUtf16beEncoding = 3,
58}
59
60/// Line break type.
61#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Debug)]
62#[repr(u32)]
63#[non_exhaustive]
64pub enum YamlBreakT {
65    /// Let the parser choose the break type.
66    YamlAnyBreak = 0,
67    /// Use CR for line breaks (Mac style).
68    YamlCrBreak = 1,
69    /// Use LN for line breaks (Unix style).
70    YamlLnBreak = 2,
71    /// Use CR LN for line breaks (DOS style).
72    YamlCrlnBreak = 3,
73}
74
75/// Many bad things could happen with the parser and emitter.
76#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Debug)]
77#[repr(u32)]
78#[non_exhaustive]
79pub enum YamlErrorTypeT {
80    /// No error.
81    YamlNoError = 0,
82    /// Cannot allocate or reallocate a block of memory.
83    YamlMemoryError = 1,
84    /// Cannot read or decode the input stream.
85    YamlReaderError = 2,
86    /// Cannot scan the input stream.
87    YamlScannerError = 3,
88    /// Cannot parse the input stream.
89    YamlParserError = 4,
90    /// Cannot compose a YAML document.
91    YamlComposerError = 5,
92    /// Cannot write to the output stream.
93    YamlWriterError = 6,
94    /// Cannot emit a YAML stream.
95    YamlEmitterError = 7,
96}
97
98impl Default for YamlErrorTypeT {
99    fn default() -> Self {
100        YamlErrorTypeT::YamlNoError
101    }
102}
103
104/// The pointer position.
105#[derive(Copy, Clone, Debug, Default)]
106#[repr(C)]
107#[non_exhaustive]
108pub struct YamlMarkT {
109    /// The position index.
110    pub index: size_t,
111    /// The position line.
112    pub line: size_t,
113    /// The position column.
114    pub column: size_t,
115}
116
117/// Scalar styles.
118#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Debug)]
119#[repr(u32)]
120#[non_exhaustive]
121pub enum YamlScalarStyleT {
122    /// Let the emitter choose the style.
123    YamlAnyScalarStyle = 0,
124    /// The plain scalar style.
125    YamlPlainScalarStyle = 1,
126    /// The single-quoted scalar style.
127    YamlSingleQuotedScalarStyle = 2,
128    /// The double-quoted scalar style.
129    YamlDoubleQuotedScalarStyle = 3,
130    /// The literal scalar style.
131    YamlLiteralScalarStyle = 4,
132    /// The folded scalar style.
133    YamlFoldedScalarStyle = 5,
134}
135
136/// Sequence styles.
137#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Debug)]
138#[repr(u32)]
139#[non_exhaustive]
140pub enum YamlSequenceStyleT {
141    /// Let the emitter choose the style.
142    YamlAnySequenceStyle = 0,
143    /// The block sequence style.
144    YamlBlockSequenceStyle = 1,
145    /// The flow sequence style.
146    YamlFlowSequenceStyle = 2,
147}
148
149/// Mapping styles.
150#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Debug)]
151#[repr(u32)]
152#[non_exhaustive]
153pub enum YamlMappingStyleT {
154    /// Let the emitter choose the style.
155    YamlAnyMappingStyle = 0,
156    /// The block mapping style.
157    YamlBlockMappingStyle = 1,
158    /// The flow mapping style.
159    YamlFlowMappingStyle = 2,
160}
161
162/// The token types.
163#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Debug)]
164#[repr(u32)]
165#[non_exhaustive]
166pub enum YamlTokenTypeT {
167    /// An empty token.
168    YamlNoToken = 0,
169    /// A stream-start token.
170    YamlStreamStartToken = 1,
171    /// A stream-end token.
172    YamlStreamEndToken = 2,
173    /// A version-directive token.
174    YamlVersionDirectiveToken = 3,
175    /// A tag-directive token.
176    YamlTagDirectiveToken = 4,
177    /// A document-start token.
178    YamlDocumentStartToken = 5,
179    /// A document-end token.
180    YamlDocumentEndToken = 6,
181    /// A block-sequence-start token.
182    YamlBlockSequenceStartToken = 7,
183    /// A block-mapping-start token.
184    YamlBlockMappingStartToken = 8,
185    /// A block-end token.
186    YamlBlockEndToken = 9,
187    /// A flow-sequence-start token.
188    YamlFlowSequenceStartToken = 10,
189    /// A flow-sequence-end token.
190    YamlFlowSequenceEndToken = 11,
191    /// A flow-mapping-start token.
192    YamlFlowMappingStartToken = 12,
193    /// A flow-mapping-end token.
194    YamlFlowMappingEndToken = 13,
195    /// A block-entry token.
196    YamlBlockEntryToken = 14,
197    /// A flow-entry token.
198    YamlFlowEntryToken = 15,
199    /// A key token.
200    YamlKeyToken = 16,
201    /// A value token.
202    YamlValueToken = 17,
203    /// An alias token.
204    YamlAliasToken = 18,
205    /// An anchor token.
206    YamlAnchorToken = 19,
207    /// A tag token.
208    YamlTagToken = 20,
209    /// A scalar token.
210    YamlScalarToken = 21,
211}
212
213/// The token structure.
214#[derive(Copy, Clone, Debug)]
215#[repr(C)]
216#[non_exhaustive]
217pub struct YamlTokenT {
218    /// The token type.
219    pub type_: YamlTokenTypeT,
220    /// The token data.
221    pub data: UnnamedYamlTokenTData,
222    /// The beginning of the token.
223    pub start_mark: YamlMarkT,
224    /// The end of the token.
225    pub end_mark: YamlMarkT,
226}
227
228#[derive(Copy, Clone, Debug, Default)]
229#[repr(C)]
230/// The data structure for YAML tokens.
231pub struct UnnamedYamlTokenTData {
232    /// The stream start (for YamlStreamStartToken).
233    pub stream_start: UnnamedYamlTokenTdataStreamStart,
234    /// The alias (for YamlAliasToken).
235    pub alias: UnnamedYamlTokenTdataAlias,
236    /// The anchor (for YamlAnchorToken).
237    pub anchor: UnnamedYamlTokenTdataAnchor,
238    /// The tag (for YamlTagToken).
239    pub tag: UnnamedYamlTokenTdataTag,
240    /// The scalar value (for YamlScalarToken).
241    pub scalar: UnnamedYamlTokenTdataScalar,
242    /// The version directive (for YamlVersionDirectiveToken).
243    pub version_directive: UnnamedYamlTokenTdataVersionDirective,
244    /// The tag directive (for YamlTagDirectiveToken).
245    pub tag_directive: UnnamedYamlTokenTdataTagDirective,
246}
247
248/// Represents the start of a YAML data stream.
249#[derive(Copy, Clone, Debug)]
250#[repr(C)]
251#[non_exhaustive]
252pub struct UnnamedYamlTokenTdataStreamStart {
253    /// The stream encoding.
254    pub encoding: YamlEncodingT,
255}
256
257/// Represents an alias in a YAML document.
258#[derive(Copy, Clone, Debug)]
259#[repr(C)]
260#[non_exhaustive]
261pub struct UnnamedYamlTokenTdataAlias {
262    /// The alias value.
263    pub value: *mut yaml_char_t,
264}
265
266/// Represents an anchor in a YAML document.
267#[derive(Copy, Clone, Debug)]
268#[repr(C)]
269#[non_exhaustive]
270pub struct UnnamedYamlTokenTdataAnchor {
271    /// The anchor value.
272    pub value: *mut yaml_char_t,
273}
274
275/// Represents a tag in a YAML document.
276#[derive(Copy, Clone, Debug)]
277#[repr(C)]
278#[non_exhaustive]
279pub struct UnnamedYamlTokenTdataTag {
280    /// The tag handle.
281    pub handle: *mut yaml_char_t,
282    /// The tag suffix.
283    pub suffix: *mut yaml_char_t,
284}
285
286/// Represents a scalar value in a YAML document.
287#[derive(Copy, Clone, Debug)]
288#[repr(C)]
289#[non_exhaustive]
290pub struct UnnamedYamlTokenTdataScalar {
291    /// The scalar value.
292    pub value: *mut yaml_char_t,
293    /// The length of the scalar value.
294    pub length: size_t,
295    /// The scalar style.
296    pub style: YamlScalarStyleT,
297}
298
299/// Represents the version directive in a YAML document.
300#[derive(Copy, Clone, Debug, Default)]
301#[repr(C)]
302#[non_exhaustive]
303pub struct UnnamedYamlTokenTdataVersionDirective {
304    /// The major version number.
305    pub major: libc::c_int,
306    /// The minor version number.
307    pub minor: libc::c_int,
308}
309
310/// Represents the tag directive in a YAML document.
311#[derive(Copy, Clone, Debug)]
312#[repr(C)]
313#[non_exhaustive]
314pub struct UnnamedYamlTokenTdataTagDirective {
315    /// The tag handle.
316    pub handle: *mut yaml_char_t,
317    /// The tag prefix.
318    pub prefix: *mut yaml_char_t,
319}
320
321/// Event types.
322#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Debug)]
323#[repr(u32)]
324#[non_exhaustive]
325pub enum YamlEventTypeT {
326    /// An empty event.
327    YamlNoEvent = 0,
328    /// A stream-start event.
329    YamlStreamStartEvent = 1,
330    /// A stream-end event.
331    YamlStreamEndEvent = 2,
332    /// A document-start event.
333    YamlDocumentStartEvent = 3,
334    /// A document-end event.
335    YamlDocumentEndEvent = 4,
336    /// An alias event.
337    YamlAliasEvent = 5,
338    /// A scalar event.
339    YamlScalarEvent = 6,
340    /// A sequence-start event.
341    YamlSequenceStartEvent = 7,
342    /// A sequence-end event.
343    YamlSequenceEndEvent = 8,
344    /// A mapping-start event.
345    YamlMappingStartEvent = 9,
346    /// A mapping-end event.
347    YamlMappingEndEvent = 10,
348}
349
350/// The event structure.
351#[derive(Copy, Clone, Debug)]
352#[repr(C)]
353#[non_exhaustive]
354pub struct YamlEventT {
355    /// The event type.
356    pub type_: YamlEventTypeT,
357    /// The event data.
358    pub data: UnnamedYamlEventTData,
359    /// The beginning of the event.
360    pub start_mark: YamlMarkT,
361    /// The end of the event.
362    pub end_mark: YamlMarkT,
363}
364
365/// Represents the data associated with a YAML event.
366#[derive(Copy, Clone, Debug)]
367#[repr(C)]
368pub struct UnnamedYamlEventTData {
369    /// The stream parameters (for YamlStreamStartEvent).
370    pub stream_start: UnnamedYamlEventTdataStreamStart,
371    /// The document parameters (for YamlDocumentStartEvent).
372    pub document_start: UnnamedYamlEventTdataDocumentStart,
373    /// The document end parameters (for YamlDocumentEndEvent).
374    pub document_end: UnnamedYamlEventTdataDocumentEnd,
375    /// The alias parameters (for YamlAliasEvent).
376    pub alias: UnnamedYamlEventTdataAlias,
377    /// The scalar parameters (for YamlScalarEvent).
378    pub scalar: UnnamedYamlEventTdataScalar,
379    /// The sequence parameters (for YamlSequenceStartEvent).
380    pub sequence_start: UnnamedYamlEventTdataSequenceStart,
381    /// The mapping parameters (for YamlMappingStartEvent).
382    pub mapping_start: UnnamedYamlEventTdataMappingStart,
383}
384
385/// Represents the data associated with the start of a YAML stream.
386#[derive(Copy, Clone, Debug)]
387#[repr(C)]
388#[non_exhaustive]
389pub struct UnnamedYamlEventTdataStreamStart {
390    /// The document encoding.
391    pub encoding: YamlEncodingT,
392}
393
394/// Represents the data associated with the start of a YAML document.
395#[derive(Copy, Clone, Debug)]
396#[repr(C)]
397#[non_exhaustive]
398pub struct UnnamedYamlEventTdataDocumentStart {
399    /// The version directive.
400    pub version_directive: *mut YamlVersionDirectiveT,
401    /// The list of tag directives.
402    pub tag_directives: UnnamedYamlEventTdataDocumentStartTagDirectives,
403    /// Is the document indicator implicit?
404    pub implicit: bool,
405}
406
407/// Represents the list of tag directives at the start of a YAML document.
408#[derive(Copy, Clone, Debug)]
409#[repr(C)]
410#[non_exhaustive]
411pub struct UnnamedYamlEventTdataDocumentStartTagDirectives {
412    /// The beginning of the tag directives list.
413    pub start: *mut YamlTagDirectiveT,
414    /// The end of the tag directives list.
415    pub end: *mut YamlTagDirectiveT,
416}
417
418/// Represents the data associated with the end of a YAML document.
419#[derive(Copy, Clone, Debug)]
420#[repr(C)]
421#[non_exhaustive]
422pub struct UnnamedYamlEventTdataDocumentEnd {
423    /// Is the document end indicator implicit?
424    pub implicit: bool,
425}
426
427/// Represents the data associated with a YAML alias event.
428#[derive(Copy, Clone, Debug)]
429#[repr(C)]
430#[non_exhaustive]
431pub struct UnnamedYamlEventTdataAlias {
432    /// The anchor.
433    pub anchor: *mut yaml_char_t,
434}
435
436/// Represents the data associated with a YAML scalar event.
437#[derive(Copy, Clone, Debug)]
438#[repr(C)]
439#[non_exhaustive]
440pub struct UnnamedYamlEventTdataScalar {
441    /// The anchor.
442    pub anchor: *mut yaml_char_t,
443    /// The tag.
444    pub tag: *mut yaml_char_t,
445    /// The scalar value.
446    pub value: *mut yaml_char_t,
447    /// The length of the scalar value.
448    pub length: size_t,
449    /// Is the tag optional for the plain style?
450    pub plain_implicit: bool,
451    /// Is the tag optional for any non-plain style?
452    pub quoted_implicit: bool,
453    /// The scalar style.
454    pub style: YamlScalarStyleT,
455}
456
457/// Represents the data associated with the start of a YAML sequence.
458#[derive(Copy, Clone, Debug)]
459#[repr(C)]
460#[non_exhaustive]
461pub struct UnnamedYamlEventTdataSequenceStart {
462    /// The anchor.
463    pub anchor: *mut yaml_char_t,
464    /// The tag.
465    pub tag: *mut yaml_char_t,
466    /// Is the tag optional?
467    pub implicit: bool,
468    /// The sequence style.
469    pub style: YamlSequenceStyleT,
470}
471
472/// Represents the data associated with the start of a YAML mapping.
473#[derive(Copy, Clone, Debug)]
474#[repr(C)]
475#[non_exhaustive]
476pub struct UnnamedYamlEventTdataMappingStart {
477    /// The anchor.
478    pub anchor: *mut yaml_char_t,
479    /// The tag.
480    pub tag: *mut yaml_char_t,
481    /// Is the tag optional?
482    pub implicit: bool,
483    /// The mapping style.
484    pub style: YamlMappingStyleT,
485}
486
487/// Node types.
488#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Debug)]
489#[repr(u32)]
490#[non_exhaustive]
491pub enum YamlNodeTypeT {
492    /// An empty node.
493    YamlNoNode = 0,
494    /// A scalar node.
495    YamlScalarNode = 1,
496    /// A sequence node.
497    YamlSequenceNode = 2,
498    /// A mapping node.
499    YamlMappingNode = 3,
500}
501
502/// The node structure.
503#[derive(Copy, Clone, Debug)]
504#[repr(C)]
505#[non_exhaustive]
506pub struct YamlNodeT {
507    /// The node type.
508    pub type_: YamlNodeTypeT,
509    /// The node tag.
510    pub tag: *mut yaml_char_t,
511    /// The node data.
512    pub data: UnnamedYamlNodeTData,
513    /// The beginning of the node.
514    pub start_mark: YamlMarkT,
515    /// The end of the node.
516    pub end_mark: YamlMarkT,
517}
518
519/// Represents the data associated with a YAML node.
520#[derive(Copy, Clone, Debug)]
521#[repr(C)]
522pub struct UnnamedYamlNodeTData {
523    /// The scalar parameters (for YamlScalarNode).
524    pub scalar: UnnamedYamlNodeTDataScalar,
525    /// The sequence parameters (for YamlSequenceNode).
526    pub sequence: UnnamedYamlNodeTDataSequence,
527    /// The mapping parameters (for YamlMappingNode).
528    pub mapping: UnnamedYamlNodeTDataMapping,
529}
530
531/// Represents the data associated with a YAML scalar node.
532#[derive(Copy, Clone, Debug)]
533#[repr(C)]
534#[non_exhaustive]
535pub struct UnnamedYamlNodeTDataScalar {
536    /// The scalar value.
537    pub value: *mut yaml_char_t,
538    /// The length of the scalar value.
539    pub length: size_t,
540    /// The scalar style.
541    pub style: YamlScalarStyleT,
542}
543
544/// Represents an element of a YAML sequence node.
545pub type YamlNodeItemT = libc::c_int;
546
547/// Represents the data associated with a YAML sequence node.
548#[derive(Copy, Clone, Debug)]
549#[repr(C)]
550#[non_exhaustive]
551pub struct UnnamedYamlNodeTDataSequence {
552    /// The stack of sequence items.
553    pub items: YamlStackT<YamlNodeItemT>,
554    /// The sequence style.
555    pub style: YamlSequenceStyleT,
556}
557
558/// Represents the data associated with a YAML mapping node.
559#[derive(Copy, Clone, Debug)]
560#[repr(C)]
561#[non_exhaustive]
562pub struct UnnamedYamlNodeTDataMapping {
563    /// The stack of mapping pairs (key, value).
564    pub pairs: YamlStackT<YamlNodePairT>,
565    /// The mapping style.
566    pub style: YamlMappingStyleT,
567}
568
569/// An element of a mapping node.
570#[derive(Copy, Clone, Debug)]
571#[repr(C)]
572#[non_exhaustive]
573pub struct YamlNodePairT {
574    /// The key of the element.
575    pub key: libc::c_int,
576    /// The value of the element.
577    pub value: libc::c_int,
578}
579
580/// The document structure.
581#[derive(Clone, Debug)]
582#[repr(C)]
583#[non_exhaustive]
584pub struct YamlDocumentT {
585    /// The document nodes.
586    pub nodes: YamlStackT<YamlNodeT>,
587    /// The version directive.
588    pub version_directive: *mut YamlVersionDirectiveT,
589    /// The list of tag directives.
590    pub tag_directives: UnnamedYamlDocumentTTagDirectives,
591    /// Is the document start indicator implicit?
592    pub start_implicit: bool,
593    /// Is the document end indicator implicit?
594    pub end_implicit: bool,
595    /// The beginning of the document.
596    pub start_mark: YamlMarkT,
597    /// The end of the document.
598    pub end_mark: YamlMarkT,
599}
600
601/// Represents the list of tag directives in a YAML document.
602#[derive(Copy, Clone, Debug)]
603#[repr(C)]
604#[non_exhaustive]
605pub struct UnnamedYamlDocumentTTagDirectives {
606    /// The beginning of the tag directives list.
607    pub start: *mut YamlTagDirectiveT,
608    /// The end of the tag directives list.
609    pub end: *mut YamlTagDirectiveT,
610}
611
612/// The prototype of a read handler.
613///
614/// The read handler is called when the parser needs to read more bytes from the
615/// source. The handler should write not more than `size` bytes to the `buffer`.
616/// The number of written bytes should be set to the `length` variable.
617///
618/// On success, the handler should return 1. If the handler failed, the returned
619/// value should be 0. On EOF, the handler should set the `size_read` to 0 and
620/// return 1.
621pub type YamlReadHandlerT = unsafe fn(
622    data: *mut libc::c_void,
623    buffer: *mut libc::c_uchar,
624    size: size_t,
625    size_read: *mut size_t,
626) -> libc::c_int;
627
628/// This structure holds information about a potential simple key.
629#[derive(Copy, Clone, Debug, Default)]
630#[repr(C)]
631#[non_exhaustive]
632pub struct YamlSimpleKeyT {
633    /// Is a simple key possible?
634    pub possible: bool,
635    /// Is a simple key required?
636    pub required: bool,
637    /// The number of the token.
638    pub token_number: size_t,
639    /// The position mark.
640    pub mark: YamlMarkT,
641}
642
643/// The states of the parser.
644#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Debug)]
645#[repr(u32)]
646#[non_exhaustive]
647pub enum YamlParserStateT {
648    /// Expect stream-start.
649    YamlParseStreamStartState = 0,
650    /// Expect the beginning of an implicit document.
651    YamlParseImplicitDocumentStartState = 1,
652    /// Expect document-start.
653    YamlParseDocumentStartState = 2,
654    /// Expect the content of a document.
655    YamlParseDocumentContentState = 3,
656    /// Expect document-end.
657    YamlParseDocumentEndState = 4,
658    /// Expect a block node.
659    YamlParseBlockNodeState = 5,
660    /// Expect a block node or indentless sequence.
661    YamlParseBlockNodeOrIndentlessSequenceState = 6,
662    /// Expect a flow node.
663    YamlParseFlowNodeState = 7,
664    /// Expect the first entry of a block sequence.
665    YamlParseBlockSequenceFirstEntryState = 8,
666    /// Expect an entry of a block sequence.
667    YamlParseBlockSequenceEntryState = 9,
668    /// Expect an entry of an indentless sequence.
669    YamlParseIndentlessSequenceEntryState = 10,
670    /// Expect the first key of a block mapping.
671    YamlParseBlockMappingFirstKeyState = 11,
672    /// Expect a block mapping key.
673    YamlParseBlockMappingKeyState = 12,
674    /// Expect a block mapping value.
675    YamlParseBlockMappingValueState = 13,
676    /// Expect the first entry of a flow sequence.
677    YamlParseFlowSequenceFirstEntryState = 14,
678    /// Expect an entry of a flow sequence.
679    YamlParseFlowSequenceEntryState = 15,
680    /// Expect a key of an ordered mapping.
681    YamlParseFlowSequenceEntryMappingKeyState = 16,
682    /// Expect a value of an ordered mapping.
683    YamlParseFlowSequenceEntryMappingValueState = 17,
684    /// Expect the and of an ordered mapping entry.
685    YamlParseFlowSequenceEntryMappingEndState = 18,
686    /// Expect the first key of a flow mapping.
687    YamlParseFlowMappingFirstKeyState = 19,
688    /// Expect a key of a flow mapping.
689    YamlParseFlowMappingKeyState = 20,
690    /// Expect a value of a flow mapping.
691    YamlParseFlowMappingValueState = 21,
692    /// Expect an empty value of a flow mapping.
693    YamlParseFlowMappingEmptyValueState = 22,
694    /// Expect nothing.
695    YamlParseEndState = 23,
696}
697
698/// This structure holds aliases data.
699#[derive(Copy, Clone, Debug)]
700#[repr(C)]
701#[non_exhaustive]
702pub struct YamlAliasDataT {
703    /// The anchor.
704    pub anchor: *mut yaml_char_t,
705    /// The node id.
706    pub index: libc::c_int,
707    /// The anchor mark.
708    pub mark: YamlMarkT,
709}
710
711/// The parser structure.
712///
713/// All members are internal. Manage the structure using the `yaml_parser_`
714/// family of functions.
715#[derive(Clone, Debug)]
716#[repr(C)]
717#[non_exhaustive]
718pub struct YamlParserT {
719    /// Error type.
720    #[cfg(doc)]
721    pub error: YamlErrorTypeT,
722    #[cfg(not(doc))]
723    pub(crate) error: YamlErrorTypeT,
724    /// Error description.
725    #[cfg(doc)]
726    pub problem: *const libc::c_char,
727    #[cfg(not(doc))]
728    pub(crate) problem: *const libc::c_char,
729    /// The byte about which the problem occurred.
730    #[cfg(doc)]
731    pub problem_offset: size_t,
732    #[cfg(not(doc))]
733    pub(crate) problem_offset: size_t,
734    /// The problematic value (-1 is none).
735    #[cfg(doc)]
736    pub problem_value: libc::c_int,
737    #[cfg(not(doc))]
738    pub(crate) problem_value: libc::c_int,
739    /// The problem position.
740    #[cfg(doc)]
741    pub problem_mark: YamlMarkT,
742    #[cfg(not(doc))]
743    pub(crate) problem_mark: YamlMarkT,
744    /// The error context.
745    #[cfg(doc)]
746    pub context: *const libc::c_char,
747    #[cfg(not(doc))]
748    pub(crate) context: *const libc::c_char,
749    /// The context position.
750    #[cfg(doc)]
751    pub context_mark: YamlMarkT,
752    #[cfg(not(doc))]
753    pub(crate) context_mark: YamlMarkT,
754    /// Read handler.
755    pub(crate) read_handler: Option<YamlReadHandlerT>,
756    /// A pointer for passing to the read handler.
757    pub(crate) read_handler_data: *mut libc::c_void,
758    /// Standard (string or file) input data.
759    pub(crate) input: UnnamedYamlParserTInput,
760    /// EOF flag
761    pub(crate) eof: bool,
762    /// The working buffer.
763    pub(crate) buffer: YamlBufferT<yaml_char_t>,
764    /// The number of unread characters in the buffer.
765    pub(crate) unread: size_t,
766    /// The raw buffer.
767    pub(crate) raw_buffer: YamlBufferT<libc::c_uchar>,
768    /// The input encoding.
769    pub(crate) encoding: YamlEncodingT,
770    /// The offset of the current position (in bytes).
771    pub(crate) offset: size_t,
772    /// The mark of the current position.
773    pub(crate) mark: YamlMarkT,
774    /// Have we started to scan the input stream?
775    pub(crate) stream_start_produced: bool,
776    /// Have we reached the end of the input stream?
777    pub(crate) stream_end_produced: bool,
778    /// The number of unclosed '[' and '{' indicators.
779    pub(crate) flow_level: libc::c_int,
780    /// The tokens queue.
781    pub(crate) tokens: YamlQueueT<YamlTokenT>,
782    /// The number of tokens fetched from the queue.
783    pub(crate) tokens_parsed: size_t,
784    /// Does the tokens queue contain a token ready for dequeueing.
785    pub(crate) token_available: bool,
786    /// The indentation levels stack.
787    pub(crate) indents: YamlStackT<libc::c_int>,
788    /// The current indentation level.
789    pub(crate) indent: libc::c_int,
790    /// May a simple key occur at the current position?
791    pub(crate) simple_key_allowed: bool,
792    /// The stack of simple keys.
793    pub(crate) simple_keys: YamlStackT<YamlSimpleKeyT>,
794    /// At least this many leading elements of simple_keys have possible=0.
795    pub(crate) not_simple_keys: libc::c_int,
796    /// The parser states stack.
797    pub(crate) states: YamlStackT<YamlParserStateT>,
798    /// The current parser state.
799    pub(crate) state: YamlParserStateT,
800    /// The stack of marks.
801    pub(crate) marks: YamlStackT<YamlMarkT>,
802    /// The list of TAG directives.
803    pub(crate) tag_directives: YamlStackT<YamlTagDirectiveT>,
804    /// The alias data.
805    pub(crate) aliases: YamlStackT<YamlAliasDataT>,
806    /// The currently parsed document.
807    pub(crate) document: *mut YamlDocumentT,
808}
809
810/// Represents the prefix data associated with a YAML parser.
811#[derive(Copy, Clone, Debug)]
812#[repr(C)]
813#[non_exhaustive]
814pub struct YamlParserTPrefix {
815    /// The error type.
816    pub error: YamlErrorTypeT,
817    /// The error description.
818    pub problem: *const libc::c_char,
819    /// The byte about which the problem occurred.
820    pub problem_offset: size_t,
821    /// The problematic value (-1 is none).
822    pub problem_value: libc::c_int,
823    /// The problem position.
824    pub problem_mark: YamlMarkT,
825    /// The error context.
826    pub context: *const libc::c_char,
827    /// The context position.
828    pub context_mark: YamlMarkT,
829}
830
831#[doc(hidden)]
832impl Deref for YamlParserT {
833    type Target = YamlParserTPrefix;
834    fn deref(&self) -> &Self::Target {
835        unsafe { &*addr_of!(*self).cast() }
836    }
837}
838
839#[derive(Copy, Clone, Debug, Default)]
840#[repr(C)]
841pub(crate) struct UnnamedYamlParserTInput {
842    /// String input data.
843    pub(crate) string: UnnamedYamlParserTInputString,
844}
845
846#[derive(Copy, Clone, Debug)]
847#[repr(C)]
848pub(crate) struct UnnamedYamlParserTInputString {
849    /// The string start pointer.
850    pub(crate) start: *const libc::c_uchar,
851    /// The string end pointer.
852    pub(crate) end: *const libc::c_uchar,
853    /// The string current position.
854    pub(crate) current: *const libc::c_uchar,
855}
856
857/// The prototype of a write handler.
858///
859/// The write handler is called when the emitter needs to flush the accumulated
860/// characters to the output. The handler should write `size` bytes of the
861/// `buffer` to the output.
862///
863/// On success, the handler should return 1. If the handler failed, the returned
864/// value should be 0.
865pub type YamlWriteHandlerT = unsafe fn(
866    data: *mut libc::c_void,
867    buffer: *mut libc::c_uchar,
868    size: size_t,
869) -> libc::c_int;
870
871/// The emitter states.
872#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Debug)]
873#[repr(u32)]
874#[non_exhaustive]
875pub enum YamlEmitterStateT {
876    /// Expect stream-start.
877    YamlEmitStreamStartState = 0,
878    /// Expect the first document-start or stream-end.
879    YamlEmitFirstDocumentStartState = 1,
880    /// Expect document-start or stream-end.
881    YamlEmitDocumentStartState = 2,
882    /// Expect the content of a document.
883    YamlEmitDocumentContentState = 3,
884    /// Expect document-end.
885    YamlEmitDocumentEndState = 4,
886    /// Expect the first item of a flow sequence.
887    YamlEmitFlowSequenceFirstItemState = 5,
888    /// Expect an item of a flow sequence.
889    YamlEmitFlowSequenceItemState = 6,
890    /// Expect the first key of a flow mapping.
891    YamlEmitFlowMappingFirstKeyState = 7,
892    /// Expect a key of a flow mapping.
893    YamlEmitFlowMappingKeyState = 8,
894    /// Expect a value for a simple key of a flow mapping.
895    YamlEmitFlowMappingSimpleValueState = 9,
896    /// Expect a value of a flow mapping.
897    YamlEmitFlowMappingValueState = 10,
898    /// Expect the first item of a block sequence.
899    YamlEmitBlockSequenceFirstItemState = 11,
900    /// Expect an item of a block sequence.
901    YamlEmitBlockSequenceItemState = 12,
902    /// Expect the first key of a block mapping.
903    YamlEmitBlockMappingFirstKeyState = 13,
904    /// Expect the key of a block mapping.
905    YamlEmitBlockMappingKeyState = 14,
906    /// Expect a value for a simple key of a block mapping.
907    YamlEmitBlockMappingSimpleValueState = 15,
908    /// Expect a value of a block mapping.
909    YamlEmitBlockMappingValueState = 16,
910    /// Expect nothing.
911    YamlEmitEndState = 17,
912}
913
914#[derive(Copy, Clone, Debug)]
915#[repr(C)]
916pub(crate) struct YamlAnchorsT {
917    /// The number of references.
918    pub(crate) references: libc::c_int,
919    /// The anchor id.
920    pub(crate) anchor: libc::c_int,
921    /// If the node has been emitted?
922    pub(crate) serialized: bool,
923}
924
925/// The emitter structure.
926///
927/// All members are internal. Manage the structure using the `yaml_emitter_`
928/// family of functions.
929#[derive(Clone, Debug)]
930#[repr(C)]
931#[non_exhaustive]
932pub struct YamlEmitterT {
933    /// Error type.
934    #[cfg(doc)]
935    pub error: YamlErrorTypeT,
936    #[cfg(not(doc))]
937    pub(crate) error: YamlErrorTypeT,
938    /// Error description.
939    #[cfg(doc)]
940    pub problem: *const libc::c_char,
941    #[cfg(not(doc))]
942    pub(crate) problem: *const libc::c_char,
943    /// Write handler.
944    pub write_handler: Option<YamlWriteHandlerT>,
945    /// A pointer for passing to the write handler.
946    pub(crate) write_handler_data: *mut libc::c_void,
947    /// Standard (string or file) output data.
948    pub output: UnnamedYamlEmitterTOutput,
949    /// The working buffer.
950    pub buffer: YamlBufferT<yaml_char_t>,
951    /// The raw buffer.
952    pub(crate) raw_buffer: YamlBufferT<libc::c_uchar>,
953    /// The stream encoding.
954    pub(crate) encoding: YamlEncodingT,
955    /// If the output is in the canonical style?
956    pub(crate) canonical: bool,
957    /// The number of indentation spaces.
958    pub(crate) best_indent: libc::c_int,
959    /// The preferred width of the output lines.
960    pub(crate) best_width: libc::c_int,
961    /// Allow unescaped non-ASCII characters?
962    pub(crate) unicode: bool,
963    /// The preferred line break.
964    pub(crate) line_break: YamlBreakT,
965    /// The stack of states.
966    pub(crate) states: YamlStackT<YamlEmitterStateT>,
967    /// The current emitter state.
968    pub(crate) state: YamlEmitterStateT,
969    /// The event queue.
970    pub(crate) events: YamlQueueT<YamlEventT>,
971    /// The stack of indentation levels.
972    pub(crate) indents: YamlStackT<libc::c_int>,
973    /// The list of tag directives.
974    pub(crate) tag_directives: YamlStackT<YamlTagDirectiveT>,
975    /// The current indentation level.
976    pub(crate) indent: libc::c_int,
977    /// The current flow level.
978    pub(crate) flow_level: libc::c_int,
979    /// Is it the document root context?
980    pub(crate) root_context: bool,
981    /// Is it a sequence context?
982    pub(crate) sequence_context: bool,
983    /// Is it a mapping context?
984    pub(crate) mapping_context: bool,
985    /// Is it a simple mapping key context?
986    pub(crate) simple_key_context: bool,
987    /// The current line.
988    pub(crate) line: libc::c_int,
989    /// The current column.
990    pub(crate) column: libc::c_int,
991    /// If the last character was a whitespace?
992    pub(crate) whitespace: bool,
993    /// If the last character was an indentation character (' ', '-', '?', ':')?
994    pub(crate) indention: bool,
995    /// If an explicit document end is required?
996    pub(crate) open_ended: libc::c_int,
997    /// Anchor analysis.
998    pub(crate) anchor_data: UnnamedYamlEmitterTAnchorData,
999    /// Tag analysis.
1000    pub(crate) tag_data: UnnamedYamlEmitterTTagData,
1001    /// Scalar analysis.
1002    pub(crate) scalar_data: UnnamedYamlEmitterTScalarData,
1003    /// If the stream was already opened?
1004    pub opened: bool,
1005    /// If the stream was already closed?
1006    pub closed: bool,
1007    /// The information associated with the document nodes.
1008    pub(crate) anchors: *mut YamlAnchorsT,
1009    /// The last assigned anchor id.
1010    pub(crate) last_anchor_id: libc::c_int,
1011    /// The currently emitted document.
1012    pub(crate) document: *mut YamlDocumentT,
1013}
1014
1015/// Represents the prefix data associated with a YAML emitter.
1016#[derive(Copy, Clone, Debug)]
1017#[repr(C)]
1018#[non_exhaustive]
1019pub struct YamlEmitterTPrefix {
1020    /// The error type.
1021    pub error: YamlErrorTypeT,
1022    /// The error description.
1023    pub problem: *const libc::c_char,
1024}
1025
1026#[doc(hidden)]
1027impl Deref for YamlEmitterT {
1028    type Target = YamlEmitterTPrefix;
1029    fn deref(&self) -> &Self::Target {
1030        unsafe { &*addr_of!(*self).cast() }
1031    }
1032}
1033
1034#[derive(Copy, Clone, Debug, Default)]
1035#[repr(C)]
1036/// Represents the output data associated with a YAML emitter.
1037pub struct UnnamedYamlEmitterTOutput {
1038    /// String output data.
1039    pub string: UnnamedYamlEmitterTOutputString,
1040}
1041
1042#[derive(Copy, Clone, Debug)]
1043#[repr(C)]
1044/// Represents the unamed output string data associated with a YAML emitter.
1045pub struct UnnamedYamlEmitterTOutputString {
1046    /// The buffer pointer.
1047    pub buffer: *mut libc::c_uchar,
1048    /// The buffer size.
1049    pub size: size_t,
1050    /// The number of written bytes.
1051    pub size_written: *mut size_t,
1052}
1053
1054#[derive(Copy, Clone, Debug)]
1055#[repr(C)]
1056pub(crate) struct UnnamedYamlEmitterTAnchorData {
1057    /// The anchor value.
1058    pub(crate) anchor: *mut yaml_char_t,
1059    /// The anchor length.
1060    pub(crate) anchor_length: size_t,
1061    /// Is it an alias?
1062    pub(crate) alias: bool,
1063}
1064
1065#[derive(Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
1066#[repr(C)]
1067pub(crate) struct UnnamedYamlEmitterTTagData {
1068    /// The tag handle.
1069    pub(crate) handle: *mut yaml_char_t,
1070    /// The tag handle length.
1071    pub(crate) handle_length: size_t,
1072    /// The tag suffix.
1073    pub(crate) suffix: *mut yaml_char_t,
1074    /// The tag suffix length.
1075    pub(crate) suffix_length: size_t,
1076}
1077
1078#[derive(Copy, Clone, Debug)]
1079#[repr(C)]
1080pub(crate) struct UnnamedYamlEmitterTScalarData {
1081    /// The scalar value.
1082    pub(crate) value: *mut yaml_char_t,
1083    /// The scalar length.
1084    pub(crate) length: size_t,
1085    /// Does the scalar contain line breaks?
1086    pub(crate) multiline: bool,
1087    /// Can the scalar be expressed in the flow plain style?
1088    pub(crate) flow_plain_allowed: bool,
1089    /// Can the scalar be expressed in the block plain style?
1090    pub(crate) block_plain_allowed: bool,
1091    /// Can the scalar be expressed in the single quoted style?
1092    pub(crate) single_quoted_allowed: bool,
1093    /// Can the scalar be expressed in the literal or folded styles?
1094    pub(crate) block_allowed: bool,
1095    /// The output style.
1096    pub(crate) style: YamlScalarStyleT,
1097}
1098
1099#[derive(Copy, Clone, Debug)]
1100#[repr(C)]
1101pub(crate) struct YamlStringT {
1102    pub(crate) start: *mut yaml_char_t,
1103    pub(crate) end: *mut yaml_char_t,
1104    pub(crate) pointer: *mut yaml_char_t,
1105}
1106
1107pub(crate) const NULL_STRING: YamlStringT = YamlStringT {
1108    start: ptr::null_mut::<yaml_char_t>(),
1109    end: ptr::null_mut::<yaml_char_t>(),
1110    pointer: ptr::null_mut::<yaml_char_t>(),
1111};
1112
1113#[derive(Copy, Clone, Debug)]
1114#[repr(C)]
1115/// Represents the data associated with a YAML token.
1116pub struct YamlBufferT<T> {
1117    /// The beginning of the buffer.
1118    pub start: *mut T,
1119    /// The end of the buffer.
1120    pub end: *mut T,
1121    /// The current position of the buffer.
1122    pub pointer: *mut T,
1123    /// The last filled position of the buffer.
1124    pub last: *mut T,
1125}
1126
1127impl<T> YamlBufferT<T> {
1128    /// Is the buffer empty?
1129    pub(crate) fn is_empty(&self) -> bool {
1130        self.pointer == self.last
1131    }
1132
1133    /// Advances the buffer by one character.
1134    pub(crate) fn next(&mut self) {
1135        if !self.is_empty() {
1136            unsafe {
1137                self.pointer = self.pointer.add(1);
1138            }
1139        }
1140    }
1141}
1142
1143impl<T> Default for YamlBufferT<T> {
1144    fn default() -> Self {
1145        YamlBufferT {
1146            start: ptr::null_mut(),
1147            end: ptr::null_mut(),
1148            pointer: ptr::null_mut(),
1149            last: ptr::null_mut(),
1150        }
1151    }
1152}
1153
1154/// The beginning of the stack.
1155#[derive(Debug)]
1156#[repr(C)]
1157pub struct YamlStackT<T> {
1158    /// The beginning of the stack.
1159    pub start: *mut T,
1160    /// The end of the stack.
1161    pub end: *mut T,
1162    /// The top of the stack.
1163    pub top: *mut T,
1164}
1165
1166impl<T> Copy for YamlStackT<T> {}
1167impl<T> Clone for YamlStackT<T> {
1168    fn clone(&self) -> Self {
1169        *self
1170    }
1171}
1172
1173/// The beginning of the queue.
1174#[derive(Debug)]
1175#[repr(C)]
1176pub(crate) struct YamlQueueT<T> {
1177    /// The beginning of the queue.
1178    pub(crate) start: *mut T,
1179    /// The end of the queue.
1180    pub(crate) end: *mut T,
1181    /// The head of the queue.
1182    pub(crate) head: *mut T,
1183    /// The tail of the queue.
1184    pub(crate) tail: *mut T,
1185}
1186
1187impl<T> Copy for YamlQueueT<T> {}
1188impl<T> Clone for YamlQueueT<T> {
1189    fn clone(&self) -> Self {
1190        *self
1191    }
1192}
1193
1194impl<T: Default> Default for YamlQueueT<T> {
1195    fn default() -> Self {
1196        YamlQueueT {
1197            start: ptr::null_mut(),
1198            end: ptr::null_mut(),
1199            head: ptr::null_mut(),
1200            tail: ptr::null_mut(),
1201        }
1202    }
1203}
1204
1205impl Default for YamlStringT {
1206    fn default() -> Self {
1207        YamlStringT {
1208            start: ptr::null_mut(),
1209            end: ptr::null_mut(),
1210            pointer: ptr::null_mut(),
1211        }
1212    }
1213}
1214
1215impl Default for UnnamedYamlEmitterTScalarData {
1216    fn default() -> Self {
1217        UnnamedYamlEmitterTScalarData {
1218            value: ptr::null_mut(),
1219            length: 0,
1220            multiline: false,
1221            flow_plain_allowed: false,
1222            block_plain_allowed: false,
1223            single_quoted_allowed: false,
1224            block_allowed: false,
1225            style: YamlScalarStyleT::YamlAnyScalarStyle,
1226        }
1227    }
1228}
1229
1230impl Default for UnnamedYamlEmitterTTagData {
1231    fn default() -> Self {
1232        UnnamedYamlEmitterTTagData {
1233            handle: ptr::null_mut(),
1234            handle_length: 0,
1235            suffix: ptr::null_mut(),
1236            suffix_length: 0,
1237        }
1238    }
1239}
1240
1241impl Default for UnnamedYamlEmitterTAnchorData {
1242    fn default() -> Self {
1243        UnnamedYamlEmitterTAnchorData {
1244            anchor: ptr::null_mut(),
1245            anchor_length: 0,
1246            alias: false,
1247        }
1248    }
1249}
1250
1251impl Default for UnnamedYamlEmitterTOutputString {
1252    fn default() -> Self {
1253        UnnamedYamlEmitterTOutputString {
1254            buffer: ptr::null_mut(),
1255            size: 0,
1256            size_written: ptr::null_mut(),
1257        }
1258    }
1259}
1260
1261impl Default for UnnamedYamlParserTInputString {
1262    fn default() -> Self {
1263        UnnamedYamlParserTInputString {
1264            start: ptr::null(),
1265            end: ptr::null(),
1266            current: ptr::null(),
1267        }
1268    }
1269}
1270
1271impl Default for UnnamedYamlDocumentTTagDirectives {
1272    fn default() -> Self {
1273        UnnamedYamlDocumentTTagDirectives {
1274            start: ptr::null_mut(),
1275            end: ptr::null_mut(),
1276        }
1277    }
1278}
1279
1280impl Default for YamlEncodingT {
1281    fn default() -> Self {
1282        YamlAnyEncoding
1283    }
1284}
1285
1286impl Default for YamlParserStateT {
1287    fn default() -> Self {
1288        YamlParserStateT::YamlParseStreamStartState
1289    }
1290}
1291
1292impl Default for YamlScalarStyleT {
1293    fn default() -> Self {
1294        YamlScalarStyleT::YamlAnyScalarStyle
1295    }
1296}
1297
1298impl Default for YamlTokenT {
1299    fn default() -> Self {
1300        YamlTokenT {
1301            type_: YamlTokenTypeT::YamlNoToken,
1302            data: UnnamedYamlTokenTData::default(),
1303            start_mark: YamlMarkT::default(),
1304            end_mark: YamlMarkT::default(),
1305        }
1306    }
1307}
1308
1309impl Default for UnnamedYamlTokenTdataStreamStart {
1310    fn default() -> Self {
1311        UnnamedYamlTokenTdataStreamStart {
1312            encoding: YamlAnyEncoding,
1313        }
1314    }
1315}
1316
1317impl Default for UnnamedYamlTokenTdataAlias {
1318    fn default() -> Self {
1319        UnnamedYamlTokenTdataAlias {
1320            value: ptr::null_mut(),
1321        }
1322    }
1323}
1324
1325impl Default for UnnamedYamlTokenTdataAnchor {
1326    fn default() -> Self {
1327        UnnamedYamlTokenTdataAnchor {
1328            value: ptr::null_mut(),
1329        }
1330    }
1331}
1332
1333impl Default for UnnamedYamlTokenTdataTag {
1334    fn default() -> Self {
1335        UnnamedYamlTokenTdataTag {
1336            handle: ptr::null_mut(),
1337            suffix: ptr::null_mut(),
1338        }
1339    }
1340}
1341
1342impl Default for UnnamedYamlTokenTdataScalar {
1343    fn default() -> Self {
1344        UnnamedYamlTokenTdataScalar {
1345            value: ptr::null_mut(),
1346            length: 0,
1347            style: YamlScalarStyleT::YamlAnyScalarStyle,
1348        }
1349    }
1350}
1351
1352impl Default for UnnamedYamlTokenTdataTagDirective {
1353    fn default() -> Self {
1354        UnnamedYamlTokenTdataTagDirective {
1355            handle: ptr::null_mut(),
1356            prefix: ptr::null_mut(),
1357        }
1358    }
1359}
1360
1361impl Default for YamlStackT<YamlSimpleKeyT> {
1362    fn default() -> Self {
1363        YamlStackT {
1364            start: ptr::null_mut(),
1365            end: ptr::null_mut(),
1366            top: ptr::null_mut(),
1367        }
1368    }
1369}
1370
1371impl Default for YamlStackT<YamlTagDirectiveT> {
1372    fn default() -> Self {
1373        YamlStackT {
1374            start: ptr::null_mut(),
1375            end: ptr::null_mut(),
1376            top: ptr::null_mut(),
1377        }
1378    }
1379}
1380
1381impl Default for YamlStackT<YamlAliasDataT> {
1382    fn default() -> Self {
1383        YamlStackT {
1384            start: ptr::null_mut(),
1385            end: ptr::null_mut(),
1386            top: ptr::null_mut(),
1387        }
1388    }
1389}
1390
1391impl Default for YamlTagDirectiveT {
1392    fn default() -> Self {
1393        YamlTagDirectiveT {
1394            handle: ptr::null_mut(),
1395            prefix: ptr::null_mut(),
1396        }
1397    }
1398}
1399
1400impl Default for YamlBreakT {
1401    fn default() -> Self {
1402        YamlBreakT::YamlAnyBreak
1403    }
1404}
1405
1406impl Default for YamlSequenceStyleT {
1407    fn default() -> Self {
1408        YamlSequenceStyleT::YamlAnySequenceStyle
1409    }
1410}
1411
1412impl Default for YamlMappingStyleT {
1413    fn default() -> Self {
1414        YamlMappingStyleT::YamlAnyMappingStyle
1415    }
1416}
1417
1418impl Default for YamlEventTypeT {
1419    fn default() -> Self {
1420        YamlNoEvent
1421    }
1422}
1423
1424impl Default for YamlAliasDataT {
1425    fn default() -> Self {
1426        YamlAliasDataT {
1427            anchor: ptr::null_mut(),
1428            index: 0,
1429            mark: YamlMarkT::default(),
1430        }
1431    }
1432}
1433
1434impl Default for YamlNodeTypeT {
1435    fn default() -> Self {
1436        YamlNoNode
1437    }
1438}
1439
1440impl Default for YamlEmitterStateT {
1441    fn default() -> Self {
1442        YamlEmitterStateT::YamlEmitStreamStartState
1443    }
1444}
1445
1446impl YamlDocumentT {
1447    /// Cleans up resources used by `YamlDocumentT`. This includes deallocating memory for
1448    /// version directives, tag directives, and nodes if they were allocated dynamically.
1449    ///
1450    /// # Safety
1451    ///
1452    /// This function is `unsafe` because it assumes that all pointers (e.g., version_directive,
1453    /// tag directives, and nodes) are either valid or null. It will attempt to free allocated
1454    /// memory, so the caller must ensure that:
1455    ///
1456    /// 1. The struct has been initialized properly.
1457    /// 2. No other code retains pointers to the data being freed here.
1458    /// 3. This method is not called concurrently with any operations that read from or write to
1459    ///    the pointed-to data.
1460    /// 4. The memory management strategy (allocation and deallocation) is correctly paired.
1461    ///    For instance, if `libc::malloc` is used to allocate, `libc::free` should be used to deallocate.
1462    ///
1463    pub unsafe fn cleanup(&mut self) {
1464        // Assuming `version_directive` and `tag_directives.start/end` are pointers that need to be freed.
1465        if !self.version_directive.is_null() {
1466            // Free version_directive if your logic requires it, e.g.,
1467            // libc::free(self.version_directive as *mut libc::c_void);
1468            self.version_directive = ptr::null_mut();
1469        }
1470
1471        // Example of cleaning up tag directives if they were allocated dynamically
1472        let mut tag_directive = self.tag_directives.start;
1473        while tag_directive < self.tag_directives.end {
1474            // Free each tag directive if necessary
1475            // libc::free((*tag_directive).handle as *mut libc::c_void);
1476            // libc::free((*tag_directive).prefix as *mut libc::c_void);
1477            tag_directive = tag_directive.offset(1);
1478        }
1479
1480        // Assuming `nodes` needs to be cleaned up
1481        let mut node = self.nodes.start;
1482        while node < self.nodes.top {
1483            // Free each node if necessary
1484            // libc::free((*node).tag as *mut libc::c_void);
1485            node = node.offset(1);
1486        }
1487
1488        // Free the nodes array itself if it was dynamically allocated
1489        // libc::free(self.nodes.start as *mut libc::c_void);
1490        self.nodes.start = ptr::null_mut();
1491        self.nodes.end = ptr::null_mut();
1492        self.nodes.top = ptr::null_mut();
1493    }
1494}
1495
1496impl Default for YamlDocumentT {
1497    fn default() -> Self {
1498        YamlDocumentT {
1499            nodes: YamlStackT {
1500                start: ptr::null_mut(),
1501                end: ptr::null_mut(),
1502                top: ptr::null_mut(),
1503            },
1504            version_directive: ptr::null_mut(),
1505            tag_directives: UnnamedYamlDocumentTTagDirectives::default(
1506            ),
1507            start_implicit: false,
1508            end_implicit: false,
1509            start_mark: YamlMarkT::default(),
1510            end_mark: YamlMarkT::default(),
1511        }
1512    }
1513}