Debian Codegraph @

src/writer/events.rs

raw symbols SCIP
1 //! Contains `XmlEvent` datatype, instances of which are consumed by the writer.
2
3 use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::borrowrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/::Cowrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/Cow#;
4
5 use craterust-analyzer cargo xml-rs 0.8.19 crate/::attributerust-analyzer cargo xml-rs 0.8.19 attribute/::Attributerust-analyzer cargo xml-rs 0.8.19 attribute/Attribute#;
6 use craterust-analyzer cargo xml-rs 0.8.19 crate/::commonrust-analyzer cargo xml-rs 0.8.19 common/::XmlVersionrust-analyzer cargo xml-rs 0.8.19 common/XmlVersion#;
7 use craterust-analyzer cargo xml-rs 0.8.19 crate/::namerust-analyzer cargo xml-rs 0.8.19 name/::Namerust-analyzer cargo xml-rs 0.8.19 name/Name#;
8 use craterust-analyzer cargo xml-rs 0.8.19 crate/::namespacerust-analyzer cargo xml-rs 0.8.19 namespace/::{Namespacerust-analyzer cargo xml-rs 0.8.19 namespace/Namespace#, NS_NO_PREFIXrust-analyzer cargo xml-rs 0.8.19 namespace/NS_NO_PREFIX.};
9
10 /// A part of an XML output stream.
11 ///
12 /// Objects of this enum are consumed by `EventWriter`. They correspond to different parts of
13 /// an XML document.
14 #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/macros/Debug:, Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone:)]
15 pub enum XmlEventrust-analyzer cargo xml-rs 0.8.19 writer/events/XmlEvent#<'a> {
16 /// Corresponds to XML document declaration.
17 ///
18 /// This event should always be written before any other event. If it is not written
19 /// at all, a default XML declaration will be outputted if the corresponding option
20 /// is set in the configuration. Otherwise an error will be returned.
21 StartDocumentrust-analyzer cargo xml-rs 0.8.19 writer/events/XmlEvent#StartDocument# {
22 /// XML version.
23 ///
24 /// Defaults to `XmlVersion::Version10`.
25 versionrust-analyzer cargo xml-rs 0.8.19 writer/events/XmlEvent#StartDocument#version.: XmlVersionrust-analyzer cargo xml-rs 0.8.19 common/XmlVersion#,
26
27 /// XML document encoding.
28 ///
29 /// Defaults to `Some("UTF-8")`.
30 encodingrust-analyzer cargo xml-rs 0.8.19 writer/events/XmlEvent#StartDocument#encoding.: Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<&'a str>,
31
32 /// XML standalone declaration.
33 ///
34 /// Defaults to `None`.
35 standalonerust-analyzer cargo xml-rs 0.8.19 writer/events/XmlEvent#StartDocument#standalone.: Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<bool>,
36 },
37
38 /// Denotes an XML processing instruction.
39 ProcessingInstructionrust-analyzer cargo xml-rs 0.8.19 writer/events/XmlEvent#ProcessingInstruction# {
40 /// Processing instruction target.
41 namerust-analyzer cargo xml-rs 0.8.19 writer/events/XmlEvent#ProcessingInstruction#name.: &'a str,
42
43 /// Processing instruction content.
44 datarust-analyzer cargo xml-rs 0.8.19 writer/events/XmlEvent#ProcessingInstruction#data.: Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<&'a str>,
45 },
46
47 /// Denotes a beginning of an XML element.
48 StartElementrust-analyzer cargo xml-rs 0.8.19 writer/events/XmlEvent#StartElement# {
49 /// Qualified name of the element.
50 namerust-analyzer cargo xml-rs 0.8.19 writer/events/XmlEvent#StartElement#name.: Namerust-analyzer cargo xml-rs 0.8.19 name/Name#<'a>,
51
52 /// A list of attributes associated with the element.
53 ///
54 /// Currently attributes are not checked for duplicates (TODO). Attribute values
55 /// will be escaped, and all characters invalid for attribute values like `"` or `<`
56 /// will be changed into character entities.
57 attributesrust-analyzer cargo xml-rs 0.8.19 writer/events/XmlEvent#StartElement#attributes.: Cowrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/Cow#<'a, [Attributerust-analyzer cargo xml-rs 0.8.19 attribute/Attribute#<'a>]>,
58
59 /// Contents of the namespace mapping at this point of the document.
60 ///
61 /// This mapping will be inspected for "new" entries, and if at this point of the document
62 /// a particular pair of prefix and namespace URI is already defined, no namespace
63 /// attributes will be emitted.
64 namespacerust-analyzer cargo xml-rs 0.8.19 writer/events/XmlEvent#StartElement#namespace.: Cowrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/Cow#<'a, Namespacerust-analyzer cargo xml-rs 0.8.19 namespace/Namespace#>,
65 },
66
67 /// Denotes an end of an XML element.
68 EndElementrust-analyzer cargo xml-rs 0.8.19 writer/events/XmlEvent#EndElement# {
69 /// Optional qualified name of the element.
70 ///
71 /// If `None`, then it is assumed that the element name should be the last valid one.
72 /// If `Some` and element names tracking is enabled, then the writer will check it for
73 /// correctness.
74 namerust-analyzer cargo xml-rs 0.8.19 writer/events/XmlEvent#EndElement#name.: Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<Namerust-analyzer cargo xml-rs 0.8.19 name/Name#<'a>>,
75 },
76
77 /// Denotes CDATA content.
78 ///
79 /// This event contains unparsed data, and no escaping will be performed when writing it
80 /// to the output stream.
81 CDatarust-analyzer cargo xml-rs 0.8.19 writer/events/XmlEvent#CData#(&'a str),
82
83 /// Denotes a comment.
84 ///
85 /// The string will be checked for invalid sequences and error will be returned by the
86 /// write operation
87 Commentrust-analyzer cargo xml-rs 0.8.19 writer/events/XmlEvent#Comment#(&'a str),
88
89 /// Denotes character data outside of tags.
90 ///
91 /// Contents of this event will be escaped if `perform_escaping` option is enabled,
92 /// that is, every character invalid for PCDATA will appear as a character entity.
93 Charactersrust-analyzer cargo xml-rs 0.8.19 writer/events/XmlEvent#Characters#(&'a str),
94 }
95
96 impl<'a> XmlEventrust-analyzer cargo xml-rs 0.8.19 writer/events/XmlEvent#<'a> {
97 /// Returns an writer event for a processing instruction.
98 #[inline]
99 #[must_use]
100 pub fn processing_instructionrust-analyzer cargo xml-rs 0.8.19 writer/events/impl#[`XmlEvent<'a>`]processing_instruction().(name: &'a str, data: Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<&'a str>) -> XmlEventrust-analyzer cargo xml-rs 0.8.19 writer/events/XmlEvent#<'a> {
101 XmlEventrust-analyzer cargo xml-rs 0.8.19 writer/events/XmlEvent#::ProcessingInstructionrust-analyzer cargo xml-rs 0.8.19 writer/events/XmlEvent#ProcessingInstruction# { namerust-analyzer cargo xml-rs 0.8.19 writer/events/XmlEvent#ProcessingInstruction#name., datarust-analyzer cargo xml-rs 0.8.19 writer/events/XmlEvent#ProcessingInstruction#data. }
102 }
103
104 /// Returns a builder for a starting element.
105 ///
106 /// This builder can then be used to tweak attributes and namespace starting at
107 /// this element.
108 #[inline]
109 pub fn start_elementrust-analyzer cargo xml-rs 0.8.19 writer/events/impl#[`XmlEvent<'a>`]start_element().<S>(name: S) -> StartElementBuilderrust-analyzer cargo xml-rs 0.8.19 writer/events/StartElementBuilder#<'a> where S: Intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/Into#<Namerust-analyzer cargo xml-rs 0.8.19 name/Name#<'a>> {
110 StartElementBuilderrust-analyzer cargo xml-rs 0.8.19 writer/events/StartElementBuilder# {
111 namerust-analyzer cargo xml-rs 0.8.19 writer/events/StartElementBuilder#name.: name.intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/Into#into().(),
112 attributesrust-analyzer cargo xml-rs 0.8.19 writer/events/StartElementBuilder#attributes.: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#::newrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T>`]new().(),
113 namespacerust-analyzer cargo xml-rs 0.8.19 writer/events/StartElementBuilder#namespace.: Namespacerust-analyzer cargo xml-rs 0.8.19 namespace/Namespace#::emptyrust-analyzer cargo xml-rs 0.8.19 namespace/impl#[Namespace]empty().(),
114 }
115 }
116
117 /// Returns a builder for an closing element.
118 ///
119 /// This method, unline `start_element()`, does not accept a name because by default
120 /// the writer is able to determine it automatically. However, when this functionality
121 /// is disabled, it is possible to specify the name with `name()` method on the builder.
122 #[inline]
123 #[must_use]
124 pub fn end_elementrust-analyzer cargo xml-rs 0.8.19 writer/events/impl#[`XmlEvent<'a>`]end_element().() -> EndElementBuilderrust-analyzer cargo xml-rs 0.8.19 writer/events/EndElementBuilder#<'a> {
125 EndElementBuilderrust-analyzer cargo xml-rs 0.8.19 writer/events/EndElementBuilder# { namerust-analyzer cargo xml-rs 0.8.19 writer/events/EndElementBuilder#name.: Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None# }
126 }
127
128 /// Returns a CDATA event.
129 ///
130 /// Naturally, the provided string won't be escaped, except for closing CDATA token `]]>`
131 /// (depending on the configuration).
132 #[inline]
133 #[must_use]
134 pub fn cdatarust-analyzer cargo xml-rs 0.8.19 writer/events/impl#[`XmlEvent<'a>`]cdata().(data: &'a str) -> XmlEventrust-analyzer cargo xml-rs 0.8.19 writer/events/XmlEvent#<'a> {
135 XmlEventrust-analyzer cargo xml-rs 0.8.19 writer/events/XmlEvent#::CDatarust-analyzer cargo xml-rs 0.8.19 writer/events/XmlEvent#CData#(data)
136 }
137
138 /// Returns a regular characters (PCDATA) event.
139 ///
140 /// All offending symbols, in particular, `&` and `<`, will be escaped by the writer.
141 #[inline]
142 #[must_use]
143 pub fn charactersrust-analyzer cargo xml-rs 0.8.19 writer/events/impl#[`XmlEvent<'a>`]characters().(data: &'a str) -> XmlEventrust-analyzer cargo xml-rs 0.8.19 writer/events/XmlEvent#<'a> {
144 XmlEventrust-analyzer cargo xml-rs 0.8.19 writer/events/XmlEvent#::Charactersrust-analyzer cargo xml-rs 0.8.19 writer/events/XmlEvent#Characters#(data)
145 }
146
147 /// Returns a comment event.
148 #[inline]
149 #[must_use]
150 pub fn commentrust-analyzer cargo xml-rs 0.8.19 writer/events/impl#[`XmlEvent<'a>`]comment().(data: &'a str) -> XmlEventrust-analyzer cargo xml-rs 0.8.19 writer/events/XmlEvent#<'a> {
151 XmlEventrust-analyzer cargo xml-rs 0.8.19 writer/events/XmlEvent#::Commentrust-analyzer cargo xml-rs 0.8.19 writer/events/XmlEvent#Comment#(data)
152 }
153 }
154
155 impl<'a> Fromrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/From#<&'a str> for XmlEventrust-analyzer cargo xml-rs 0.8.19 writer/events/XmlEvent#<'a> {
156 #[inline]
157 fn fromrust-analyzer cargo xml-rs 0.8.19 writer/events/impl#[`XmlEvent<'a>`][`From<&'a str>`]from().(s: &'a str) -> XmlEventrust-analyzer cargo xml-rs 0.8.19 writer/events/XmlEvent#<'a> {
158 XmlEventrust-analyzer cargo xml-rs 0.8.19 writer/events/XmlEvent#::Charactersrust-analyzer cargo xml-rs 0.8.19 writer/events/XmlEvent#Characters#(s)
159 }
160 }
161
162 pub struct EndElementBuilderrust-analyzer cargo xml-rs 0.8.19 writer/events/EndElementBuilder#<'a> {
163 namerust-analyzer cargo xml-rs 0.8.19 writer/events/EndElementBuilder#name.: Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<Namerust-analyzer cargo xml-rs 0.8.19 name/Name#<'a>>,
164 }
165
166 /// A builder for a closing element event.
167 impl<'a> EndElementBuilderrust-analyzer cargo xml-rs 0.8.19 writer/events/EndElementBuilder#<'a> {
168 /// Sets the name of this closing element.
169 ///
170 /// Usually the writer is able to determine closing element names automatically. If
171 /// this functionality is enabled (by default it is), then this name is checked for correctness.
172 /// It is possible, however, to disable such behavior; then the user must ensure that
173 /// closing element name is correct manually.
174 #[inline]
175 pub fn namerust-analyzer cargo xml-rs 0.8.19 writer/events/impl#[`EndElementBuilder<'a>`]name().<N>(mut self, name: N) -> EndElementBuilderrust-analyzer cargo xml-rs 0.8.19 writer/events/EndElementBuilder#<'a> where N: Intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/Into#<Namerust-analyzer cargo xml-rs 0.8.19 name/Name#<'a>> {
176 self.namerust-analyzer cargo xml-rs 0.8.19 writer/events/EndElementBuilder#name. = Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(name.intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/Into#into().());
177 self
178 }
179 }
180
181 impl<'a> Fromrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/From#<EndElementBuilderrust-analyzer cargo xml-rs 0.8.19 writer/events/EndElementBuilder#<'a>> for XmlEventrust-analyzer cargo xml-rs 0.8.19 writer/events/XmlEvent#<'a> {
182 fn fromrust-analyzer cargo xml-rs 0.8.19 writer/events/impl#[`XmlEvent<'a>`][`From<EndElementBuilder<'a>>`]from().(b: EndElementBuilderrust-analyzer cargo xml-rs 0.8.19 writer/events/EndElementBuilder#<'a>) -> XmlEventrust-analyzer cargo xml-rs 0.8.19 writer/events/XmlEvent#<'a> {
183 XmlEventrust-analyzer cargo xml-rs 0.8.19 writer/events/XmlEvent#::EndElementrust-analyzer cargo xml-rs 0.8.19 writer/events/XmlEvent#EndElement# { namerust-analyzer cargo xml-rs 0.8.19 writer/events/XmlEvent#EndElement#name.: b.namerust-analyzer cargo xml-rs 0.8.19 writer/events/EndElementBuilder#name. }
184 }
185 }
186
187 /// A builder for a starting element event.
188 pub struct StartElementBuilderrust-analyzer cargo xml-rs 0.8.19 writer/events/StartElementBuilder#<'a> {
189 namerust-analyzer cargo xml-rs 0.8.19 writer/events/StartElementBuilder#name.: Namerust-analyzer cargo xml-rs 0.8.19 name/Name#<'a>,
190 attributesrust-analyzer cargo xml-rs 0.8.19 writer/events/StartElementBuilder#attributes.: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<Attributerust-analyzer cargo xml-rs 0.8.19 attribute/Attribute#<'a>>,
191 namespacerust-analyzer cargo xml-rs 0.8.19 writer/events/StartElementBuilder#namespace.: Namespacerust-analyzer cargo xml-rs 0.8.19 namespace/Namespace#,
192 }
193
194 impl<'a> StartElementBuilderrust-analyzer cargo xml-rs 0.8.19 writer/events/StartElementBuilder#<'a> {
195 /// Sets an attribute value of this element to the given string.
196 ///
197 /// This method can be used to add attributes to the starting element. Name is a qualified
198 /// name; its namespace is ignored, but its prefix is checked for correctness, that is,
199 /// it is checked that the prefix is bound to some namespace in the current context.
200 ///
201 /// Currently attributes are not checked for duplicates. Note that duplicate attributes
202 /// are a violation of XML document well-formedness.
203 ///
204 /// The writer checks that you don't specify reserved prefix names, for example `xmlns`.
205 #[inline]
206 pub fn attrrust-analyzer cargo xml-rs 0.8.19 writer/events/impl#[`StartElementBuilder<'a>`]attr().<N>(mut self, name: N, value: &'a str) -> StartElementBuilderrust-analyzer cargo xml-rs 0.8.19 writer/events/StartElementBuilder#<'a>
207 where N: Intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/Into#<Namerust-analyzer cargo xml-rs 0.8.19 name/Name#<'a>>
208 {
209 self.attributesrust-analyzer cargo xml-rs 0.8.19 writer/events/StartElementBuilder#attributes..pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]push().(Attributerust-analyzer cargo xml-rs 0.8.19 attribute/Attribute#::newrust-analyzer cargo xml-rs 0.8.19 attribute/impl#[`Attribute<'a>`]new().(name.intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/Into#into().(), value));
210 self
211 }
212
213 /// Adds a namespace to the current namespace context.
214 ///
215 /// If no namespace URI was bound to the provided prefix at this point of the document,
216 /// then the mapping from the prefix to the provided namespace URI will be written as
217 /// a part of this element attribute set.
218 ///
219 /// If the same namespace URI was bound to the provided prefix at this point of the document,
220 /// then no namespace attributes will be emitted.
221 ///
222 /// If some other namespace URI was bound to the provided prefix at this point of the document,
223 /// then another binding will be added as a part of this element attribute set, shadowing
224 /// the outer binding.
225 #[inline]
226 #[must_use]
227 pub fn nsrust-analyzer cargo xml-rs 0.8.19 writer/events/impl#[`StartElementBuilder<'a>`]ns().<S1, S2>(mut self, prefix: S1, uri: S2) -> StartElementBuilderrust-analyzer cargo xml-rs 0.8.19 writer/events/StartElementBuilder#<'a>
228 where S1: Intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/Into#<Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#>, S2: Intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/Into#<Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#>
229 {
230 self.namespacerust-analyzer cargo xml-rs 0.8.19 writer/events/StartElementBuilder#namespace..putrust-analyzer cargo xml-rs 0.8.19 namespace/impl#[Namespace]put().(prefix, uri);
231 self
232 }
233
234 /// Adds a default namespace mapping to the current namespace context.
235 ///
236 /// Same rules as for `ns()` are also valid for the default namespace mapping.
237 #[inline]
238 #[must_use]
239 pub fn default_nsrust-analyzer cargo xml-rs 0.8.19 writer/events/impl#[`StartElementBuilder<'a>`]default_ns().<S>(mut self, uri: S) -> StartElementBuilderrust-analyzer cargo xml-rs 0.8.19 writer/events/StartElementBuilder#<'a>
240 where S: Intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/Into#<Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#>
241 {
242 self.namespacerust-analyzer cargo xml-rs 0.8.19 writer/events/StartElementBuilder#namespace..putrust-analyzer cargo xml-rs 0.8.19 namespace/impl#[Namespace]put().(NS_NO_PREFIXrust-analyzer cargo xml-rs 0.8.19 namespace/NS_NO_PREFIX., uri);
243 self
244 }
245 }
246
247 impl<'a> Fromrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/From#<StartElementBuilderrust-analyzer cargo xml-rs 0.8.19 writer/events/StartElementBuilder#<'a>> for XmlEventrust-analyzer cargo xml-rs 0.8.19 writer/events/XmlEvent#<'a> {
248 #[inline]
249 fn fromrust-analyzer cargo xml-rs 0.8.19 writer/events/impl#[`XmlEvent<'a>`][`From<StartElementBuilder<'a>>`]from().(b: StartElementBuilderrust-analyzer cargo xml-rs 0.8.19 writer/events/StartElementBuilder#<'a>) -> XmlEventrust-analyzer cargo xml-rs 0.8.19 writer/events/XmlEvent#<'a> {
250 XmlEventrust-analyzer cargo xml-rs 0.8.19 writer/events/XmlEvent#::StartElementrust-analyzer cargo xml-rs 0.8.19 writer/events/XmlEvent#StartElement# {
251 namerust-analyzer cargo xml-rs 0.8.19 writer/events/XmlEvent#StartElement#name.: b.namerust-analyzer cargo xml-rs 0.8.19 writer/events/StartElementBuilder#name.,
252 attributesrust-analyzer cargo xml-rs 0.8.19 writer/events/XmlEvent#StartElement#attributes.: Cowrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/Cow#::Ownedrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/Cow#Owned#(b.attributesrust-analyzer cargo xml-rs 0.8.19 writer/events/StartElementBuilder#attributes.),
253 namespacerust-analyzer cargo xml-rs 0.8.19 writer/events/XmlEvent#StartElement#namespace.: Cowrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/Cow#::Ownedrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/Cow#Owned#(b.namespacerust-analyzer cargo xml-rs 0.8.19 writer/events/StartElementBuilder#namespace.),
254 }
255 }
256 }