| 1 | use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::errorrust-analyzer cargo std https://github.com/rust-lang/rust/library/std error/::Errorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core error/Error#; |
| 2 | use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::fmtrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/; |
| 3 | use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/; |
| 4 | use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::preluderust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/prelude/::*; |
| 5 | use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/; |
| 6 | |
| 7 | 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#; |
| 8 | use craterust-analyzer cargo xml-rs 0.8.19 crate/::commonrust-analyzer cargo xml-rs 0.8.19 common/; |
| 9 | 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#; |
| 10 | use craterust-analyzer cargo xml-rs 0.8.19 crate/::escaperust-analyzer cargo xml-rs 0.8.19 escape/::{AttributeEscapesrust-analyzer cargo xml-rs 0.8.19 escape/AttributeEscapes#, Escapedrust-analyzer cargo xml-rs 0.8.19 escape/Escaped#, PcDataEscapesrust-analyzer cargo xml-rs 0.8.19 escape/PcDataEscapes#}; |
| 11 | 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#, OwnedNamerust-analyzer cargo xml-rs 0.8.19 name/OwnedName#}; |
| 12 | use craterust-analyzer cargo xml-rs 0.8.19 crate/::namespacerust-analyzer cargo xml-rs 0.8.19 namespace/::{NamespaceStackrust-analyzer cargo xml-rs 0.8.19 namespace/NamespaceStack#, NS_EMPTY_URIrust-analyzer cargo xml-rs 0.8.19 namespace/NS_EMPTY_URI., NS_NO_PREFIXrust-analyzer cargo xml-rs 0.8.19 namespace/NS_NO_PREFIX., NS_XMLNS_PREFIXrust-analyzer cargo xml-rs 0.8.19 namespace/NS_XMLNS_PREFIX., NS_XML_PREFIXrust-analyzer cargo xml-rs 0.8.19 namespace/NS_XML_PREFIX.}; |
| 13 | |
| 14 | use craterust-analyzer cargo xml-rs 0.8.19 crate/::writerrust-analyzer cargo xml-rs 0.8.19 writer/::configrust-analyzer cargo xml-rs 0.8.19 writer/config/::EmitterConfigrust-analyzer cargo xml-rs 0.8.19 writer/config/EmitterConfig#; |
| 15 | |
| 16 | /// An error which may be returned by `XmlWriter` when writing XML events. |
| 17 | #[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:)] |
| 18 | pub enum EmitterErrorrust-analyzer cargo xml-rs 0.8.19 writer/emitter/EmitterError# { |
| 19 | /// An I/O error occured in the underlying `Write` instance. |
| 20 | Iorust-analyzer cargo xml-rs 0.8.19 writer/emitter/EmitterError#Io#(iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::Errorrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/Error#), |
| 21 | |
| 22 | /// Document declaration has already been written to the output stream. |
| 23 | DocumentStartAlreadyEmittedrust-analyzer cargo xml-rs 0.8.19 writer/emitter/EmitterError#DocumentStartAlreadyEmitted#, |
| 24 | |
| 25 | /// The name of the last opening element is not available. |
| 26 | LastElementNameNotAvailablerust-analyzer cargo xml-rs 0.8.19 writer/emitter/EmitterError#LastElementNameNotAvailable#, |
| 27 | |
| 28 | /// The name of the last opening element is not equal to the name of the provided |
| 29 | /// closing element. |
| 30 | EndElementNameIsNotEqualToLastStartElementNamerust-analyzer cargo xml-rs 0.8.19 writer/emitter/EmitterError#EndElementNameIsNotEqualToLastStartElementName#, |
| 31 | |
| 32 | /// End element name is not specified when it is needed, for example, when automatic |
| 33 | /// closing is not enabled in configuration. |
| 34 | EndElementNameIsNotSpecifiedrust-analyzer cargo xml-rs 0.8.19 writer/emitter/EmitterError#EndElementNameIsNotSpecified#, |
| 35 | } |
| 36 | |
| 37 | impl Fromrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/From#<iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::Errorrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/Error#> for EmitterErrorrust-analyzer cargo xml-rs 0.8.19 writer/emitter/EmitterError# { |
| 38 | #[cold] |
| 39 | fn fromrust-analyzer cargo xml-rs 0.8.19 writer/emitter/impl#[EmitterError][`From<io::Error>`]from().(err: iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::Errorrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/Error#) -> EmitterErrorrust-analyzer cargo xml-rs 0.8.19 writer/emitter/EmitterError# { |
| 40 | EmitterErrorrust-analyzer cargo xml-rs 0.8.19 writer/emitter/EmitterError#::Iorust-analyzer cargo xml-rs 0.8.19 writer/emitter/EmitterError#Io#(err) |
| 41 | } |
| 42 | } |
| 43 | |
| 44 | impl fmtrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/::Displayrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Display# for EmitterErrorrust-analyzer cargo xml-rs 0.8.19 writer/emitter/EmitterError# { |
| 45 | #[cold] |
| 46 | fn fmtrust-analyzer cargo xml-rs 0.8.19 writer/emitter/impl#[EmitterError][Display]fmt().(&self, f: &mut fmtrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/::Formatterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Formatter#<'_>) -> fmtrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/::Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Result# { |
| 47 | f.write_strrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/impl#[`Formatter<'a>`]write_str().("emitter error: ")?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 48 | match self { |
| 49 | EmitterErrorrust-analyzer cargo xml-rs 0.8.19 writer/emitter/EmitterError#::Iorust-analyzer cargo xml-rs 0.8.19 writer/emitter/EmitterError#Io#(e) => writerust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/write!!(f, "I/O error: {e}"), |
| 50 | EmitterErrorrust-analyzer cargo xml-rs 0.8.19 writer/emitter/EmitterError#::DocumentStartAlreadyEmittedrust-analyzer cargo xml-rs 0.8.19 writer/emitter/EmitterError#DocumentStartAlreadyEmitted# => f.write_strrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/impl#[`Formatter<'a>`]write_str().("document start event has already been emitted"), |
| 51 | EmitterErrorrust-analyzer cargo xml-rs 0.8.19 writer/emitter/EmitterError#::LastElementNameNotAvailablerust-analyzer cargo xml-rs 0.8.19 writer/emitter/EmitterError#LastElementNameNotAvailable# => f.write_strrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/impl#[`Formatter<'a>`]write_str().("last element name is not available"), |
| 52 | EmitterErrorrust-analyzer cargo xml-rs 0.8.19 writer/emitter/EmitterError#::EndElementNameIsNotEqualToLastStartElementNamerust-analyzer cargo xml-rs 0.8.19 writer/emitter/EmitterError#EndElementNameIsNotEqualToLastStartElementName# => f.write_strrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/impl#[`Formatter<'a>`]write_str().("end element name is not equal to last start element name"), |
| 53 | EmitterErrorrust-analyzer cargo xml-rs 0.8.19 writer/emitter/EmitterError#::EndElementNameIsNotSpecifiedrust-analyzer cargo xml-rs 0.8.19 writer/emitter/EmitterError#EndElementNameIsNotSpecified# => f.write_strrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/impl#[`Formatter<'a>`]write_str().("end element name is not specified and can't be inferred"), |
| 54 | } |
| 55 | } |
| 56 | } |
| 57 | |
| 58 | impl Errorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core error/Error# for EmitterErrorrust-analyzer cargo xml-rs 0.8.19 writer/emitter/EmitterError# { |
| 59 | } |
| 60 | |
| 61 | /// A result type yielded by `XmlWriter`. |
| 62 | pub type Resultrust-analyzer cargo xml-rs 0.8.19 writer/emitter/Result#<T, E = EmitterErrorrust-analyzer cargo xml-rs 0.8.19 writer/emitter/EmitterError#> = resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/::Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<T, E>; |
| 63 | |
| 64 | // TODO: split into a low-level fast writer without any checks and formatting logic and a |
| 65 | // high-level indenting validating writer |
| 66 | pub struct Emitterrust-analyzer cargo xml-rs 0.8.19 writer/emitter/Emitter# { |
| 67 | configrust-analyzer cargo xml-rs 0.8.19 writer/emitter/Emitter#config.: EmitterConfigrust-analyzer cargo xml-rs 0.8.19 writer/config/EmitterConfig#, |
| 68 | |
| 69 | nstrust-analyzer cargo xml-rs 0.8.19 writer/emitter/Emitter#nst.: NamespaceStackrust-analyzer cargo xml-rs 0.8.19 namespace/NamespaceStack#, |
| 70 | |
| 71 | indent_levelrust-analyzer cargo xml-rs 0.8.19 writer/emitter/Emitter#indent_level.: usize, |
| 72 | indent_stackrust-analyzer cargo xml-rs 0.8.19 writer/emitter/Emitter#indent_stack.: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<IndentFlagsrust-analyzer cargo xml-rs 0.8.19 writer/emitter/IndentFlags#>, |
| 73 | |
| 74 | element_namesrust-analyzer cargo xml-rs 0.8.19 writer/emitter/Emitter#element_names.: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<OwnedNamerust-analyzer cargo xml-rs 0.8.19 name/OwnedName#>, |
| 75 | |
| 76 | start_document_emittedrust-analyzer cargo xml-rs 0.8.19 writer/emitter/Emitter#start_document_emitted.: bool, |
| 77 | just_wrote_start_elementrust-analyzer cargo xml-rs 0.8.19 writer/emitter/Emitter#just_wrote_start_element.: bool, |
| 78 | } |
| 79 | |
| 80 | impl Emitterrust-analyzer cargo xml-rs 0.8.19 writer/emitter/Emitter# { |
| 81 | pub fn newrust-analyzer cargo xml-rs 0.8.19 writer/emitter/impl#[Emitter]new().(config: EmitterConfigrust-analyzer cargo xml-rs 0.8.19 writer/config/EmitterConfig#) -> Emitterrust-analyzer cargo xml-rs 0.8.19 writer/emitter/Emitter# { |
| 82 | let mut indent_stack = Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#::with_capacityrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T>`]with_capacity().(16); |
| 83 | indent_stack.pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]push().(IndentFlagsrust-analyzer cargo xml-rs 0.8.19 writer/emitter/IndentFlags#::WroteNothingrust-analyzer cargo xml-rs 0.8.19 writer/emitter/IndentFlags#WroteNothing#); |
| 84 | |
| 85 | Emitterrust-analyzer cargo xml-rs 0.8.19 writer/emitter/Emitter# { |
| 86 | configrust-analyzer cargo xml-rs 0.8.19 writer/emitter/Emitter#config., |
| 87 | |
| 88 | nstrust-analyzer cargo xml-rs 0.8.19 writer/emitter/Emitter#nst.: NamespaceStackrust-analyzer cargo xml-rs 0.8.19 namespace/NamespaceStack#::emptyrust-analyzer cargo xml-rs 0.8.19 namespace/impl#[NamespaceStack]empty().(), |
| 89 | |
| 90 | indent_levelrust-analyzer cargo xml-rs 0.8.19 writer/emitter/Emitter#indent_level.: 0, |
| 91 | indent_stackrust-analyzer cargo xml-rs 0.8.19 writer/emitter/Emitter#indent_stack., |
| 92 | |
| 93 | element_namesrust-analyzer cargo xml-rs 0.8.19 writer/emitter/Emitter#element_names.: 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().(), |
| 94 | |
| 95 | start_document_emittedrust-analyzer cargo xml-rs 0.8.19 writer/emitter/Emitter#start_document_emitted.: false, |
| 96 | just_wrote_start_elementrust-analyzer cargo xml-rs 0.8.19 writer/emitter/Emitter#just_wrote_start_element.: false, |
| 97 | } |
| 98 | } |
| 99 | } |
| 100 | |
| 101 | #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Copyrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Copy:, Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone:, Eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Eq:, PartialEqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq:, Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/macros/Debug:)] |
| 102 | enum IndentFlagsrust-analyzer cargo xml-rs 0.8.19 writer/emitter/IndentFlags# { |
| 103 | WroteNothingrust-analyzer cargo xml-rs 0.8.19 writer/emitter/IndentFlags#WroteNothing#, |
| 104 | WroteMarkuprust-analyzer cargo xml-rs 0.8.19 writer/emitter/IndentFlags#WroteMarkup#, |
| 105 | WroteTextrust-analyzer cargo xml-rs 0.8.19 writer/emitter/IndentFlags#WroteText#, |
| 106 | } |
| 107 | |
| 108 | impl Emitterrust-analyzer cargo xml-rs 0.8.19 writer/emitter/Emitter# { |
| 109 | /// Returns the current state of namespaces. |
| 110 | #[inline] |
| 111 | pub fn namespace_stack_mutrust-analyzer cargo xml-rs 0.8.19 writer/emitter/impl#[Emitter]namespace_stack_mut().(&mut self) -> &mut NamespaceStackrust-analyzer cargo xml-rs 0.8.19 namespace/NamespaceStack# { |
| 112 | &mut self.nstrust-analyzer cargo xml-rs 0.8.19 writer/emitter/Emitter#nst. |
| 113 | } |
| 114 | |
| 115 | #[inline] |
| 116 | fn wrote_textrust-analyzer cargo xml-rs 0.8.19 writer/emitter/impl#[Emitter]wrote_text().(&self) -> bool { |
| 117 | self.indent_stackrust-analyzer cargo xml-rs 0.8.19 writer/emitter/Emitter#indent_stack..lastrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]last().().map_orrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]map_or().(false, |&e| e rust-analyzer cargo xml-rs 0.8.19 writer/emitter/impl#[IndentFlags][`PartialEq<Self>`]eq().==rust-analyzer cargo xml-rs 0.8.19 writer/emitter/impl#[IndentFlags][`PartialEq<Self>`]eq(). rust-analyzer cargo xml-rs 0.8.19 writer/emitter/impl#[IndentFlags][`PartialEq<Self>`]eq().IndentFlagsrust-analyzer cargo xml-rs 0.8.19 writer/emitter/IndentFlags#::WroteTextrust-analyzer cargo xml-rs 0.8.19 writer/emitter/IndentFlags#WroteText#) |
| 118 | } |
| 119 | |
| 120 | #[inline] |
| 121 | fn wrote_markuprust-analyzer cargo xml-rs 0.8.19 writer/emitter/impl#[Emitter]wrote_markup().(&self) -> bool { |
| 122 | self.indent_stackrust-analyzer cargo xml-rs 0.8.19 writer/emitter/Emitter#indent_stack..lastrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]last().().map_orrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]map_or().(false, |&e| e rust-analyzer cargo xml-rs 0.8.19 writer/emitter/impl#[IndentFlags][`PartialEq<Self>`]eq().==rust-analyzer cargo xml-rs 0.8.19 writer/emitter/impl#[IndentFlags][`PartialEq<Self>`]eq(). rust-analyzer cargo xml-rs 0.8.19 writer/emitter/impl#[IndentFlags][`PartialEq<Self>`]eq().IndentFlagsrust-analyzer cargo xml-rs 0.8.19 writer/emitter/IndentFlags#::WroteMarkuprust-analyzer cargo xml-rs 0.8.19 writer/emitter/IndentFlags#WroteMarkup#) |
| 123 | } |
| 124 | |
| 125 | #[inline] |
| 126 | fn set_wrote_textrust-analyzer cargo xml-rs 0.8.19 writer/emitter/impl#[Emitter]set_wrote_text().(&mut self) { |
| 127 | if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(e) = self.indent_stackrust-analyzer cargo xml-rs 0.8.19 writer/emitter/Emitter#indent_stack..last_mutrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]last_mut().() { |
| 128 | *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&mut T`][Deref]deref().e = IndentFlagsrust-analyzer cargo xml-rs 0.8.19 writer/emitter/IndentFlags#::WroteTextrust-analyzer cargo xml-rs 0.8.19 writer/emitter/IndentFlags#WroteText#; |
| 129 | } |
| 130 | } |
| 131 | |
| 132 | #[inline] |
| 133 | fn set_wrote_markuprust-analyzer cargo xml-rs 0.8.19 writer/emitter/impl#[Emitter]set_wrote_markup().(&mut self) { |
| 134 | if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(e) = self.indent_stackrust-analyzer cargo xml-rs 0.8.19 writer/emitter/Emitter#indent_stack..last_mutrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]last_mut().() { |
| 135 | *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&mut T`][Deref]deref().e = IndentFlagsrust-analyzer cargo xml-rs 0.8.19 writer/emitter/IndentFlags#::WroteMarkuprust-analyzer cargo xml-rs 0.8.19 writer/emitter/IndentFlags#WroteMarkup#; |
| 136 | } |
| 137 | } |
| 138 | |
| 139 | fn write_newlinerust-analyzer cargo xml-rs 0.8.19 writer/emitter/impl#[Emitter]write_newline().<W: Writerust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/Write#>(&mut self, target: &mut W, level: usize) -> Resultrust-analyzer cargo xml-rs 0.8.19 writer/emitter/Result#<()> { |
| 140 | target.write_allrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/Write#write_all().(self.configrust-analyzer cargo xml-rs 0.8.19 writer/emitter/Emitter#config..line_separatorrust-analyzer cargo xml-rs 0.8.19 writer/config/EmitterConfig#line_separator..as_bytesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]as_bytes().())?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 141 | for _ in 0..rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Range#level { |
| 142 | target.write_allrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/Write#write_all().(self.configrust-analyzer cargo xml-rs 0.8.19 writer/emitter/Emitter#config..indent_stringrust-analyzer cargo xml-rs 0.8.19 writer/config/EmitterConfig#indent_string..as_bytesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]as_bytes().())?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 143 | } |
| 144 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(()) |
| 145 | } |
| 146 | |
| 147 | fn before_markuprust-analyzer cargo xml-rs 0.8.19 writer/emitter/impl#[Emitter]before_markup().<W: Writerust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/Write#>(&mut self, target: &mut W) -> Resultrust-analyzer cargo xml-rs 0.8.19 writer/emitter/Result#<()> { |
| 148 | if self.configrust-analyzer cargo xml-rs 0.8.19 writer/emitter/Emitter#config..perform_indentrust-analyzer cargo xml-rs 0.8.19 writer/config/EmitterConfig#perform_indent. && !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().self.wrote_textrust-analyzer cargo xml-rs 0.8.19 writer/emitter/impl#[Emitter]wrote_text().() && |
| 149 | (self.indent_levelrust-analyzer cargo xml-rs 0.8.19 writer/emitter/Emitter#indent_level. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]gt().>rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]gt(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]gt().0 || self.wrote_markuprust-analyzer cargo xml-rs 0.8.19 writer/emitter/impl#[Emitter]wrote_markup().()) { |
| 150 | let indent_level = self.indent_levelrust-analyzer cargo xml-rs 0.8.19 writer/emitter/Emitter#indent_level.; |
| 151 | self.write_newlinerust-analyzer cargo xml-rs 0.8.19 writer/emitter/impl#[Emitter]write_newline().(target, indent_level)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 152 | if self.indent_levelrust-analyzer cargo xml-rs 0.8.19 writer/emitter/Emitter#indent_level. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]gt().>rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]gt(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]gt().0 && self.configrust-analyzer cargo xml-rs 0.8.19 writer/emitter/Emitter#config..indent_stringrust-analyzer cargo xml-rs 0.8.19 writer/config/EmitterConfig#indent_string..lenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]len().() rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]gt().>rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]gt(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]gt().0 { |
| 153 | self.after_markuprust-analyzer cargo xml-rs 0.8.19 writer/emitter/impl#[Emitter]after_markup().(); |
| 154 | } |
| 155 | } |
| 156 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(()) |
| 157 | } |
| 158 | |
| 159 | fn after_markuprust-analyzer cargo xml-rs 0.8.19 writer/emitter/impl#[Emitter]after_markup().(&mut self) { |
| 160 | self.set_wrote_markuprust-analyzer cargo xml-rs 0.8.19 writer/emitter/impl#[Emitter]set_wrote_markup().(); |
| 161 | } |
| 162 | |
| 163 | fn before_start_elementrust-analyzer cargo xml-rs 0.8.19 writer/emitter/impl#[Emitter]before_start_element().<W: Writerust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/Write#>(&mut self, target: &mut W) -> Resultrust-analyzer cargo xml-rs 0.8.19 writer/emitter/Result#<()> { |
| 164 | self.before_markuprust-analyzer cargo xml-rs 0.8.19 writer/emitter/impl#[Emitter]before_markup().(target)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 165 | self.indent_stackrust-analyzer cargo xml-rs 0.8.19 writer/emitter/Emitter#indent_stack..pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]push().(IndentFlagsrust-analyzer cargo xml-rs 0.8.19 writer/emitter/IndentFlags#::WroteNothingrust-analyzer cargo xml-rs 0.8.19 writer/emitter/IndentFlags#WroteNothing#); |
| 166 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(()) |
| 167 | } |
| 168 | |
| 169 | fn after_start_elementrust-analyzer cargo xml-rs 0.8.19 writer/emitter/impl#[Emitter]after_start_element().(&mut self) { |
| 170 | self.after_markuprust-analyzer cargo xml-rs 0.8.19 writer/emitter/impl#[Emitter]after_markup().(); |
| 171 | self.indent_levelrust-analyzer cargo xml-rs 0.8.19 writer/emitter/Emitter#indent_level. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign().+=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign().1; |
| 172 | } |
| 173 | |
| 174 | fn before_end_elementrust-analyzer cargo xml-rs 0.8.19 writer/emitter/impl#[Emitter]before_end_element().<W: Writerust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/Write#>(&mut self, target: &mut W) -> Resultrust-analyzer cargo xml-rs 0.8.19 writer/emitter/Result#<()> { |
| 175 | if self.configrust-analyzer cargo xml-rs 0.8.19 writer/emitter/Emitter#config..perform_indentrust-analyzer cargo xml-rs 0.8.19 writer/config/EmitterConfig#perform_indent. && self.indent_levelrust-analyzer cargo xml-rs 0.8.19 writer/emitter/Emitter#indent_level. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]gt().>rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]gt(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]gt().0 && self.wrote_markuprust-analyzer cargo xml-rs 0.8.19 writer/emitter/impl#[Emitter]wrote_markup().() && |
| 176 | !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().self.wrote_textrust-analyzer cargo xml-rs 0.8.19 writer/emitter/impl#[Emitter]wrote_text().() { |
| 177 | let indent_level = self.indent_levelrust-analyzer cargo xml-rs 0.8.19 writer/emitter/Emitter#indent_level.; |
| 178 | self.write_newlinerust-analyzer cargo xml-rs 0.8.19 writer/emitter/impl#[Emitter]write_newline().(target, indent_level rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub().-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub().1) |
| 179 | } else { |
| 180 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(()) |
| 181 | } |
| 182 | } |
| 183 | |
| 184 | fn after_end_elementrust-analyzer cargo xml-rs 0.8.19 writer/emitter/impl#[Emitter]after_end_element().(&mut self) { |
| 185 | if self.indent_levelrust-analyzer cargo xml-rs 0.8.19 writer/emitter/Emitter#indent_level. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]gt().>rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]gt(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]gt().0 { |
| 186 | self.indent_levelrust-analyzer cargo xml-rs 0.8.19 writer/emitter/Emitter#indent_level. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`SubAssign<Self>`]sub_assign().-=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`SubAssign<Self>`]sub_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`SubAssign<Self>`]sub_assign().1; |
| 187 | self.indent_stackrust-analyzer cargo xml-rs 0.8.19 writer/emitter/Emitter#indent_stack..poprust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]pop().(); |
| 188 | } |
| 189 | self.set_wrote_markuprust-analyzer cargo xml-rs 0.8.19 writer/emitter/impl#[Emitter]set_wrote_markup().(); |
| 190 | } |
| 191 | |
| 192 | fn after_textrust-analyzer cargo xml-rs 0.8.19 writer/emitter/impl#[Emitter]after_text().(&mut self) { |
| 193 | self.set_wrote_textrust-analyzer cargo xml-rs 0.8.19 writer/emitter/impl#[Emitter]set_wrote_text().(); |
| 194 | } |
| 195 | |
| 196 | pub fn emit_start_documentrust-analyzer cargo xml-rs 0.8.19 writer/emitter/impl#[Emitter]emit_start_document().<W: Writerust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/Write#>(&mut self, target: &mut W, |
| 197 | version: XmlVersionrust-analyzer cargo xml-rs 0.8.19 common/XmlVersion#, |
| 198 | encoding: &str, |
| 199 | standalone: Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<bool>) -> Resultrust-analyzer cargo xml-rs 0.8.19 writer/emitter/Result#<()> { |
| 200 | if self.start_document_emittedrust-analyzer cargo xml-rs 0.8.19 writer/emitter/Emitter#start_document_emitted. { |
| 201 | return Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(EmitterErrorrust-analyzer cargo xml-rs 0.8.19 writer/emitter/EmitterError#::DocumentStartAlreadyEmittedrust-analyzer cargo xml-rs 0.8.19 writer/emitter/EmitterError#DocumentStartAlreadyEmitted#); |
| 202 | } |
| 203 | self.start_document_emittedrust-analyzer cargo xml-rs 0.8.19 writer/emitter/Emitter#start_document_emitted. = true; |
| 204 | |
| 205 | self.before_markuprust-analyzer cargo xml-rs 0.8.19 writer/emitter/impl#[Emitter]before_markup().(target)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 206 | let result = { |
| 207 | let mut write = move || { |
| 208 | writerust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/write!!(target, "<?xml version=\"{version}\" encoding=\"{encoding}\"")?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 209 | |
| 210 | if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(standalone) = standalone { |
| 211 | writerust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/write!!(target, " standalone=\"{}\"", if standalone { "yes" } else { "no" })?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 212 | } |
| 213 | |
| 214 | writerust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/write!!(target, "?>")?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 215 | |
| 216 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(()) |
| 217 | }; |
| 218 | write() |
| 219 | }; |
| 220 | self.after_markuprust-analyzer cargo xml-rs 0.8.19 writer/emitter/impl#[Emitter]after_markup().(); |
| 221 | |
| 222 | result |
| 223 | } |
| 224 | |
| 225 | fn check_document_startedrust-analyzer cargo xml-rs 0.8.19 writer/emitter/impl#[Emitter]check_document_started().<W: Writerust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/Write#>(&mut self, target: &mut W) -> Resultrust-analyzer cargo xml-rs 0.8.19 writer/emitter/Result#<()> { |
| 226 | if !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().self.start_document_emittedrust-analyzer cargo xml-rs 0.8.19 writer/emitter/Emitter#start_document_emitted. && self.configrust-analyzer cargo xml-rs 0.8.19 writer/emitter/Emitter#config..write_document_declarationrust-analyzer cargo xml-rs 0.8.19 writer/config/EmitterConfig#write_document_declaration. { |
| 227 | self.emit_start_documentrust-analyzer cargo xml-rs 0.8.19 writer/emitter/impl#[Emitter]emit_start_document().(target, commonrust-analyzer cargo xml-rs 0.8.19 common/::XmlVersionrust-analyzer cargo xml-rs 0.8.19 common/XmlVersion#::Version10rust-analyzer cargo xml-rs 0.8.19 common/XmlVersion#Version10#, "utf-8", Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#) |
| 228 | } else { |
| 229 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(()) |
| 230 | } |
| 231 | } |
| 232 | |
| 233 | fn fix_non_empty_elementrust-analyzer cargo xml-rs 0.8.19 writer/emitter/impl#[Emitter]fix_non_empty_element().<W: Writerust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/Write#>(&mut self, target: &mut W) -> Resultrust-analyzer cargo xml-rs 0.8.19 writer/emitter/Result#<()> { |
| 234 | if self.configrust-analyzer cargo xml-rs 0.8.19 writer/emitter/Emitter#config..normalize_empty_elementsrust-analyzer cargo xml-rs 0.8.19 writer/config/EmitterConfig#normalize_empty_elements. && self.just_wrote_start_elementrust-analyzer cargo xml-rs 0.8.19 writer/emitter/Emitter#just_wrote_start_element. { |
| 235 | self.just_wrote_start_elementrust-analyzer cargo xml-rs 0.8.19 writer/emitter/Emitter#just_wrote_start_element. = false; |
| 236 | target.write_allrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/Write#write_all().(b">").map_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]map_err().(Fromrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/From#::fromrust-analyzer cargo xml-rs 0.8.19 writer/emitter/impl#[EmitterError][`From<io::Error>`]from().) |
| 237 | } else { |
| 238 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(()) |
| 239 | } |
| 240 | } |
| 241 | |
| 242 | pub fn emit_processing_instructionrust-analyzer cargo xml-rs 0.8.19 writer/emitter/impl#[Emitter]emit_processing_instruction().<W: Writerust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/Write#>(&mut self, |
| 243 | target: &mut W, |
| 244 | name: &str, |
| 245 | data: Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<&str>) -> Resultrust-analyzer cargo xml-rs 0.8.19 writer/emitter/Result#<()> { |
| 246 | self.check_document_startedrust-analyzer cargo xml-rs 0.8.19 writer/emitter/impl#[Emitter]check_document_started().(target)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 247 | self.fix_non_empty_elementrust-analyzer cargo xml-rs 0.8.19 writer/emitter/impl#[Emitter]fix_non_empty_element().(target)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 248 | |
| 249 | self.before_markuprust-analyzer cargo xml-rs 0.8.19 writer/emitter/impl#[Emitter]before_markup().(target)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 250 | |
| 251 | let result = { |
| 252 | let mut write = move || { |
| 253 | writerust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/write!!(target, "<?{name}")?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 254 | |
| 255 | if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(data) = data { |
| 256 | writerust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/write!!(target, " {data}")?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 257 | } |
| 258 | |
| 259 | writerust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/write!!(target, "?>")?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 260 | |
| 261 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(()) |
| 262 | }; |
| 263 | write() |
| 264 | }; |
| 265 | |
| 266 | self.after_markuprust-analyzer cargo xml-rs 0.8.19 writer/emitter/impl#[Emitter]after_markup().(); |
| 267 | |
| 268 | result |
| 269 | } |
| 270 | |
| 271 | fn emit_start_element_initialrust-analyzer cargo xml-rs 0.8.19 writer/emitter/impl#[Emitter]emit_start_element_initial().<W>(&mut self, target: &mut W, |
| 272 | name: Namerust-analyzer cargo xml-rs 0.8.19 name/Name#<'_>, |
| 273 | attributes: &[Attributerust-analyzer cargo xml-rs 0.8.19 attribute/Attribute#<'_>]) -> Resultrust-analyzer cargo xml-rs 0.8.19 writer/emitter/Result#<()> |
| 274 | where W: Writerust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/Write# |
| 275 | { |
| 276 | self.check_document_startedrust-analyzer cargo xml-rs 0.8.19 writer/emitter/impl#[Emitter]check_document_started().(target)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 277 | self.fix_non_empty_elementrust-analyzer cargo xml-rs 0.8.19 writer/emitter/impl#[Emitter]fix_non_empty_element().(target)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 278 | self.before_start_elementrust-analyzer cargo xml-rs 0.8.19 writer/emitter/impl#[Emitter]before_start_element().(target)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 279 | writerust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/write!!(target, "<{}", name.repr_displayrust-analyzer cargo xml-rs 0.8.19 name/impl#[`Name<'a>`]repr_display().())?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 280 | self.emit_current_namespace_attributesrust-analyzer cargo xml-rs 0.8.19 writer/emitter/impl#[Emitter]emit_current_namespace_attributes().(target)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 281 | self.emit_attributesrust-analyzer cargo xml-rs 0.8.19 writer/emitter/impl#[Emitter]emit_attributes().(target, attributes)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 282 | self.after_start_elementrust-analyzer cargo xml-rs 0.8.19 writer/emitter/impl#[Emitter]after_start_element().(); |
| 283 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(()) |
| 284 | } |
| 285 | |
| 286 | pub fn emit_start_elementrust-analyzer cargo xml-rs 0.8.19 writer/emitter/impl#[Emitter]emit_start_element().<W>(&mut self, target: &mut W, |
| 287 | name: Namerust-analyzer cargo xml-rs 0.8.19 name/Name#<'_>, |
| 288 | attributes: &[Attributerust-analyzer cargo xml-rs 0.8.19 attribute/Attribute#<'_>]) -> Resultrust-analyzer cargo xml-rs 0.8.19 writer/emitter/Result#<()> |
| 289 | where W: Writerust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/Write# |
| 290 | { |
| 291 | if self.configrust-analyzer cargo xml-rs 0.8.19 writer/emitter/Emitter#config..keep_element_names_stackrust-analyzer cargo xml-rs 0.8.19 writer/config/EmitterConfig#keep_element_names_stack. { |
| 292 | self.element_namesrust-analyzer cargo xml-rs 0.8.19 writer/emitter/Emitter#element_names..pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]push().(name.to_ownedrust-analyzer cargo xml-rs 0.8.19 name/impl#[`Name<'a>`]to_owned().()); |
| 293 | } |
| 294 | |
| 295 | self.emit_start_element_initialrust-analyzer cargo xml-rs 0.8.19 writer/emitter/impl#[Emitter]emit_start_element_initial().(target, name, attributes)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 296 | self.just_wrote_start_elementrust-analyzer cargo xml-rs 0.8.19 writer/emitter/Emitter#just_wrote_start_element. = true; |
| 297 | |
| 298 | if !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().self.configrust-analyzer cargo xml-rs 0.8.19 writer/emitter/Emitter#config..normalize_empty_elementsrust-analyzer cargo xml-rs 0.8.19 writer/config/EmitterConfig#normalize_empty_elements. { |
| 299 | writerust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/write!!(target, ">")?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 300 | } |
| 301 | |
| 302 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(()) |
| 303 | } |
| 304 | |
| 305 | pub fn emit_current_namespace_attributesrust-analyzer cargo xml-rs 0.8.19 writer/emitter/impl#[Emitter]emit_current_namespace_attributes().<W>(&mut self, target: &mut W) -> Resultrust-analyzer cargo xml-rs 0.8.19 writer/emitter/Result#<()> |
| 306 | where W: Writerust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/Write# |
| 307 | { |
| 308 | for (prefix, uri) in self.nstrust-analyzer cargo xml-rs 0.8.19 writer/emitter/Emitter#nst..peekrust-analyzer cargo xml-rs 0.8.19 namespace/impl#[NamespaceStack]peek().() { |
| 309 | match prefix { |
| 310 | // internal namespaces are not emitted |
| 311 | NS_XMLNS_PREFIXrust-analyzer cargo xml-rs 0.8.19 namespace/NS_XMLNS_PREFIX. | NS_XML_PREFIXrust-analyzer cargo xml-rs 0.8.19 namespace/NS_XML_PREFIX. => Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(()), |
| 312 | //// there is already a namespace binding with this prefix in scope |
| 313 | //prefix if self.nst.get(prefix) == Some(uri) => Ok(()), |
| 314 | // emit xmlns only if it is overridden |
| 315 | NS_NO_PREFIXrust-analyzer cargo xml-rs 0.8.19 namespace/NS_NO_PREFIX. => if uri rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialEq<&B>`]ne().!=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialEq<&B>`]ne(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialEq<&B>`]ne().NS_EMPTY_URIrust-analyzer cargo xml-rs 0.8.19 namespace/NS_EMPTY_URI. { |
| 316 | writerust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/write!!(target, " xmlns=\"{uri}\"") |
| 317 | } else { Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(()) }, |
| 318 | // everything else |
| 319 | prefix => writerust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/write!!(target, " xmlns:{prefix}=\"{uri}\"") |
| 320 | }?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 321 | } |
| 322 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(()) |
| 323 | } |
| 324 | |
| 325 | pub fn emit_attributesrust-analyzer cargo xml-rs 0.8.19 writer/emitter/impl#[Emitter]emit_attributes().<W: Writerust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/Write#>(&mut self, target: &mut W, |
| 326 | attributes: &[Attributerust-analyzer cargo xml-rs 0.8.19 attribute/Attribute#<'_>]) -> Resultrust-analyzer cargo xml-rs 0.8.19 writer/emitter/Result#<()> { |
| 327 | for attr in attributes.iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter().() { |
| 328 | writerust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/write!!(target, " {}=\"", attr.namerust-analyzer cargo xml-rs 0.8.19 attribute/Attribute#name..repr_displayrust-analyzer cargo xml-rs 0.8.19 name/impl#[`Name<'a>`]repr_display().())?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 329 | if self.configrust-analyzer cargo xml-rs 0.8.19 writer/emitter/Emitter#config..perform_escapingrust-analyzer cargo xml-rs 0.8.19 writer/config/EmitterConfig#perform_escaping. { |
| 330 | writerust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/write!!(target, "{}", Escapedrust-analyzer cargo xml-rs 0.8.19 escape/Escaped#::<AttributeEscapesrust-analyzer cargo xml-rs 0.8.19 escape/AttributeEscapes#>::newrust-analyzer cargo xml-rs 0.8.19 escape/impl#[`Escaped<'a, E>`]new().(attr.valuerust-analyzer cargo xml-rs 0.8.19 attribute/Attribute#value.))?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 331 | } else { |
| 332 | writerust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/write!!(target, "{}", attr.valuerust-analyzer cargo xml-rs 0.8.19 attribute/Attribute#value.)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 333 | } |
| 334 | writerust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/write!!(target, "\"")?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 335 | } |
| 336 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(()) |
| 337 | } |
| 338 | |
| 339 | pub fn emit_end_elementrust-analyzer cargo xml-rs 0.8.19 writer/emitter/impl#[Emitter]emit_end_element().<W: Writerust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/Write#>(&mut self, target: &mut W, |
| 340 | 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#<'_>>) -> Resultrust-analyzer cargo xml-rs 0.8.19 writer/emitter/Result#<()> { |
| 341 | let owned_name = if self.configrust-analyzer cargo xml-rs 0.8.19 writer/emitter/Emitter#config..keep_element_names_stackrust-analyzer cargo xml-rs 0.8.19 writer/config/EmitterConfig#keep_element_names_stack. { |
| 342 | Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(self.element_namesrust-analyzer cargo xml-rs 0.8.19 writer/emitter/Emitter#element_names..poprust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]pop().().ok_orrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]ok_or().(EmitterErrorrust-analyzer cargo xml-rs 0.8.19 writer/emitter/EmitterError#::LastElementNameNotAvailablerust-analyzer cargo xml-rs 0.8.19 writer/emitter/EmitterError#LastElementNameNotAvailable#)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().) |
| 343 | } else { |
| 344 | Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None# |
| 345 | }; |
| 346 | |
| 347 | // Check that last started element name equals to the provided name, if there are both |
| 348 | if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(ref last_name) = owned_name { |
| 349 | if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(ref name) = name { |
| 350 | if last_name.borrowrust-analyzer cargo xml-rs 0.8.19 name/impl#[OwnedName]borrow().() rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq#ne().!=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq#ne(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq#ne().*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&T`][Deref]deref().name { |
| 351 | return Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(EmitterErrorrust-analyzer cargo xml-rs 0.8.19 writer/emitter/EmitterError#::EndElementNameIsNotEqualToLastStartElementNamerust-analyzer cargo xml-rs 0.8.19 writer/emitter/EmitterError#EndElementNameIsNotEqualToLastStartElementName#); |
| 352 | } |
| 353 | } |
| 354 | } |
| 355 | |
| 356 | if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(name) = owned_name.as_refrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]as_ref().().maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]map().(|n| n.borrowrust-analyzer cargo xml-rs 0.8.19 name/impl#[OwnedName]borrow().()).orrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]or().(name) { |
| 357 | if self.configrust-analyzer cargo xml-rs 0.8.19 writer/emitter/Emitter#config..normalize_empty_elementsrust-analyzer cargo xml-rs 0.8.19 writer/config/EmitterConfig#normalize_empty_elements. && self.just_wrote_start_elementrust-analyzer cargo xml-rs 0.8.19 writer/emitter/Emitter#just_wrote_start_element. { |
| 358 | self.just_wrote_start_elementrust-analyzer cargo xml-rs 0.8.19 writer/emitter/Emitter#just_wrote_start_element. = false; |
| 359 | let termination = if self.configrust-analyzer cargo xml-rs 0.8.19 writer/emitter/Emitter#config..pad_self_closingrust-analyzer cargo xml-rs 0.8.19 writer/config/EmitterConfig#pad_self_closing. { " />" } else { "/>" }; |
| 360 | let result = target.write_allrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/Write#write_all().(termination.as_bytesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]as_bytes().()).map_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]map_err().(Fromrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/From#::fromrust-analyzer cargo xml-rs 0.8.19 writer/emitter/impl#[EmitterError][`From<io::Error>`]from().); |
| 361 | self.after_end_elementrust-analyzer cargo xml-rs 0.8.19 writer/emitter/impl#[Emitter]after_end_element().(); |
| 362 | result |
| 363 | } else { |
| 364 | self.just_wrote_start_elementrust-analyzer cargo xml-rs 0.8.19 writer/emitter/Emitter#just_wrote_start_element. = false; |
| 365 | |
| 366 | self.before_end_elementrust-analyzer cargo xml-rs 0.8.19 writer/emitter/impl#[Emitter]before_end_element().(target)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 367 | let result = writerust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/write!!(target, "</{}>", name.repr_displayrust-analyzer cargo xml-rs 0.8.19 name/impl#[`Name<'a>`]repr_display().()).map_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]map_err().(Fromrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/From#::fromrust-analyzer cargo xml-rs 0.8.19 writer/emitter/impl#[EmitterError][`From<io::Error>`]from().); |
| 368 | self.after_end_elementrust-analyzer cargo xml-rs 0.8.19 writer/emitter/impl#[Emitter]after_end_element().(); |
| 369 | |
| 370 | result |
| 371 | } |
| 372 | } else { |
| 373 | Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(EmitterErrorrust-analyzer cargo xml-rs 0.8.19 writer/emitter/EmitterError#::EndElementNameIsNotSpecifiedrust-analyzer cargo xml-rs 0.8.19 writer/emitter/EmitterError#EndElementNameIsNotSpecified#) |
| 374 | } |
| 375 | } |
| 376 | |
| 377 | pub fn emit_cdatarust-analyzer cargo xml-rs 0.8.19 writer/emitter/impl#[Emitter]emit_cdata().<W: Writerust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/Write#>(&mut self, target: &mut W, content: &str) -> Resultrust-analyzer cargo xml-rs 0.8.19 writer/emitter/Result#<()> { |
| 378 | self.fix_non_empty_elementrust-analyzer cargo xml-rs 0.8.19 writer/emitter/impl#[Emitter]fix_non_empty_element().(target)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 379 | if self.configrust-analyzer cargo xml-rs 0.8.19 writer/emitter/Emitter#config..cdata_to_charactersrust-analyzer cargo xml-rs 0.8.19 writer/config/EmitterConfig#cdata_to_characters. { |
| 380 | self.emit_charactersrust-analyzer cargo xml-rs 0.8.19 writer/emitter/impl#[Emitter]emit_characters().(target, content) |
| 381 | } else { |
| 382 | // TODO: escape ']]>' characters in CDATA as two adjacent CDATA blocks |
| 383 | target.write_allrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/Write#write_all().(b"<![CDATA[")?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 384 | target.write_allrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/Write#write_all().(content.as_bytesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]as_bytes().())?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 385 | target.write_allrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/Write#write_all().(b"]]>")?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 386 | |
| 387 | self.after_textrust-analyzer cargo xml-rs 0.8.19 writer/emitter/impl#[Emitter]after_text().(); |
| 388 | |
| 389 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(()) |
| 390 | } |
| 391 | } |
| 392 | |
| 393 | pub fn emit_charactersrust-analyzer cargo xml-rs 0.8.19 writer/emitter/impl#[Emitter]emit_characters().<W: Writerust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/Write#>(&mut self, target: &mut W, content: &str) -> Resultrust-analyzer cargo xml-rs 0.8.19 writer/emitter/Result#<()> { |
| 394 | self.check_document_startedrust-analyzer cargo xml-rs 0.8.19 writer/emitter/impl#[Emitter]check_document_started().(target)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 395 | self.fix_non_empty_elementrust-analyzer cargo xml-rs 0.8.19 writer/emitter/impl#[Emitter]fix_non_empty_element().(target)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 396 | |
| 397 | if self.configrust-analyzer cargo xml-rs 0.8.19 writer/emitter/Emitter#config..perform_escapingrust-analyzer cargo xml-rs 0.8.19 writer/config/EmitterConfig#perform_escaping. { |
| 398 | writerust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/write!!(target, "{}", Escapedrust-analyzer cargo xml-rs 0.8.19 escape/Escaped#::<PcDataEscapesrust-analyzer cargo xml-rs 0.8.19 escape/PcDataEscapes#>::newrust-analyzer cargo xml-rs 0.8.19 escape/impl#[`Escaped<'a, E>`]new().(content))?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 399 | } else { |
| 400 | target.write_allrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/Write#write_all().(content.as_bytesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]as_bytes().())?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 401 | } |
| 402 | |
| 403 | self.after_textrust-analyzer cargo xml-rs 0.8.19 writer/emitter/impl#[Emitter]after_text().(); |
| 404 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(()) |
| 405 | } |
| 406 | |
| 407 | pub fn emit_commentrust-analyzer cargo xml-rs 0.8.19 writer/emitter/impl#[Emitter]emit_comment().<W: Writerust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/Write#>(&mut self, target: &mut W, content: &str) -> Resultrust-analyzer cargo xml-rs 0.8.19 writer/emitter/Result#<()> { |
| 408 | self.fix_non_empty_elementrust-analyzer cargo xml-rs 0.8.19 writer/emitter/impl#[Emitter]fix_non_empty_element().(target)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 409 | |
| 410 | // TODO: add escaping dashes at the end of the comment |
| 411 | |
| 412 | let autopad_comments = self.configrust-analyzer cargo xml-rs 0.8.19 writer/emitter/Emitter#config..autopad_commentsrust-analyzer cargo xml-rs 0.8.19 writer/config/EmitterConfig#autopad_comments.; |
| 413 | let write = move |target: &mut W| -> Resultrust-analyzer cargo xml-rs 0.8.19 writer/emitter/Result#<()> { |
| 414 | target.write_allrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/Write#write_all().(b"<!--")?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 415 | |
| 416 | if autopad_comments && !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().content.starts_withrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]starts_with().(char::is_whitespacerust-analyzer cargo core https://github.com/rust-lang/rust/library/core char/methods/impl#[char]is_whitespace().) { |
| 417 | target.write_allrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/Write#write_all().(b" ")?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 418 | } |
| 419 | |
| 420 | target.write_allrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/Write#write_all().(content.as_bytesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]as_bytes().())?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 421 | |
| 422 | if autopad_comments && !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().content.ends_withrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]ends_with().(char::is_whitespacerust-analyzer cargo core https://github.com/rust-lang/rust/library/core char/methods/impl#[char]is_whitespace().) { |
| 423 | target.write_allrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/Write#write_all().(b" ")?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 424 | } |
| 425 | |
| 426 | target.write_allrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/Write#write_all().(b"-->")?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 427 | |
| 428 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(()) |
| 429 | }; |
| 430 | |
| 431 | self.before_markuprust-analyzer cargo xml-rs 0.8.19 writer/emitter/impl#[Emitter]before_markup().(target)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 432 | let result = write(target); |
| 433 | self.after_markuprust-analyzer cargo xml-rs 0.8.19 writer/emitter/impl#[Emitter]after_markup().(); |
| 434 | |
| 435 | result |
| 436 | } |
| 437 | } |