| 1 | //! Contains high-level interface for an events-based XML emitter. |
| 2 | //! |
| 3 | //! The most important type in this module is `EventWriter` which allows writing an XML document |
| 4 | //! to some output stream. |
| 5 | |
| 6 | pub use selfrust-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#; |
| 7 | pub use selfrust-analyzer cargo xml-rs 0.8.19 writer/::emitterrust-analyzer cargo xml-rs 0.8.19 writer/emitter/::EmitterErrorrust-analyzer cargo xml-rs 0.8.19 writer/emitter/EmitterError# as Errorrust-analyzer cargo xml-rs 0.8.19 writer/emitter/EmitterError#; |
| 8 | pub use selfrust-analyzer cargo xml-rs 0.8.19 writer/::emitterrust-analyzer cargo xml-rs 0.8.19 writer/emitter/::Resultrust-analyzer cargo xml-rs 0.8.19 writer/emitter/Result#; |
| 9 | pub use selfrust-analyzer cargo xml-rs 0.8.19 writer/::eventsrust-analyzer cargo xml-rs 0.8.19 writer/events/::XmlEventrust-analyzer cargo xml-rs 0.8.19 writer/events/XmlEvent#; |
| 10 | |
| 11 | use selfrust-analyzer cargo xml-rs 0.8.19 writer/::emitterrust-analyzer cargo xml-rs 0.8.19 writer/emitter/::Emitterrust-analyzer cargo xml-rs 0.8.19 writer/emitter/Emitter#; |
| 12 | |
| 13 | 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/::*; |
| 14 | |
| 15 | mod configrust-analyzer cargo xml-rs 0.8.19 writer/config/; |
| 16 | mod emitterrust-analyzer cargo xml-rs 0.8.19 writer/emitter/; |
| 17 | pub mod eventsrust-analyzer cargo xml-rs 0.8.19 writer/events/; |
| 18 | |
| 19 | /// A wrapper around an `std::io::Write` instance which emits XML document according to provided |
| 20 | /// events. |
| 21 | pub struct EventWriterrust-analyzer cargo xml-rs 0.8.19 writer/EventWriter#<W> { |
| 22 | sinkrust-analyzer cargo xml-rs 0.8.19 writer/EventWriter#sink.: W, |
| 23 | emitterrust-analyzer cargo xml-rs 0.8.19 writer/EventWriter#emitter.: Emitterrust-analyzer cargo xml-rs 0.8.19 writer/emitter/Emitter#, |
| 24 | } |
| 25 | |
| 26 | impl<W: Writerust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/Write#> EventWriterrust-analyzer cargo xml-rs 0.8.19 writer/EventWriter#<W> { |
| 27 | /// Creates a new `EventWriter` out of an `std::io::Write` instance using the default |
| 28 | /// configuration. |
| 29 | #[inline] |
| 30 | pub fn newrust-analyzer cargo xml-rs 0.8.19 writer/impl#[`EventWriter<W>`]new().(sink: W) -> EventWriterrust-analyzer cargo xml-rs 0.8.19 writer/EventWriter#<W> { |
| 31 | EventWriterrust-analyzer cargo xml-rs 0.8.19 writer/EventWriter#::new_with_configrust-analyzer cargo xml-rs 0.8.19 writer/impl#[`EventWriter<W>`]new_with_config().(sink, EmitterConfigrust-analyzer cargo xml-rs 0.8.19 writer/config/EmitterConfig#::newrust-analyzer cargo xml-rs 0.8.19 writer/config/impl#[EmitterConfig]new().()) |
| 32 | } |
| 33 | |
| 34 | /// Creates a new `EventWriter` out of an `std::io::Write` instance using the provided |
| 35 | /// configuration. |
| 36 | #[inline] |
| 37 | pub fn new_with_configrust-analyzer cargo xml-rs 0.8.19 writer/impl#[`EventWriter<W>`]new_with_config().(sink: W, config: EmitterConfigrust-analyzer cargo xml-rs 0.8.19 writer/config/EmitterConfig#) -> EventWriterrust-analyzer cargo xml-rs 0.8.19 writer/EventWriter#<W> { |
| 38 | EventWriterrust-analyzer cargo xml-rs 0.8.19 writer/EventWriter# { |
| 39 | sinkrust-analyzer cargo xml-rs 0.8.19 writer/EventWriter#sink., |
| 40 | emitterrust-analyzer cargo xml-rs 0.8.19 writer/EventWriter#emitter.: Emitterrust-analyzer cargo xml-rs 0.8.19 writer/emitter/Emitter#::newrust-analyzer cargo xml-rs 0.8.19 writer/emitter/impl#[Emitter]new().(config), |
| 41 | } |
| 42 | } |
| 43 | |
| 44 | /// Writes the next piece of XML document according to the provided event. |
| 45 | /// |
| 46 | /// Note that output data may not exactly correspond to the written event because |
| 47 | /// of various configuration options. For example, `XmlEvent::EndElement` may |
| 48 | /// correspond to a separate closing element or it may cause writing an empty element. |
| 49 | /// Another example is that `XmlEvent::CData` may be represented as characters in |
| 50 | /// the output stream. |
| 51 | pub fn writerust-analyzer cargo xml-rs 0.8.19 writer/impl#[`EventWriter<W>`]write().<'a, E>(&mut self, event: E) -> Resultrust-analyzer cargo xml-rs 0.8.19 writer/emitter/Result#<()> where E: Intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/Into#<XmlEventrust-analyzer cargo xml-rs 0.8.19 writer/events/XmlEvent#<'a>> { |
| 52 | match event.intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/Into#into().() { |
| 53 | XmlEventrust-analyzer cargo xml-rs 0.8.19 writer/events/XmlEvent#::StartDocumentrust-analyzer cargo xml-rs 0.8.19 writer/events/XmlEvent#StartDocument# { versionrust-analyzer cargo xml-rs 0.8.19 writer/events/XmlEvent#StartDocument#version., encodingrust-analyzer cargo xml-rs 0.8.19 writer/events/XmlEvent#StartDocument#encoding., standalonerust-analyzer cargo xml-rs 0.8.19 writer/events/XmlEvent#StartDocument#standalone. } => |
| 54 | self.emitterrust-analyzer cargo xml-rs 0.8.19 writer/EventWriter#emitter..emit_start_documentrust-analyzer cargo xml-rs 0.8.19 writer/emitter/impl#[Emitter]emit_start_document().(&mut self.sinkrust-analyzer cargo xml-rs 0.8.19 writer/EventWriter#sink., version, encoding.unwrap_orrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap_or().("UTF-8"), standalone), |
| 55 | 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. } => |
| 56 | self.emitterrust-analyzer cargo xml-rs 0.8.19 writer/EventWriter#emitter..emit_processing_instructionrust-analyzer cargo xml-rs 0.8.19 writer/emitter/impl#[Emitter]emit_processing_instruction().(&mut self.sinkrust-analyzer cargo xml-rs 0.8.19 writer/EventWriter#sink., name, data), |
| 57 | XmlEventrust-analyzer cargo xml-rs 0.8.19 writer/events/XmlEvent#::StartElementrust-analyzer cargo xml-rs 0.8.19 writer/events/XmlEvent#StartElement# { namerust-analyzer cargo xml-rs 0.8.19 writer/events/XmlEvent#StartElement#name., attributesrust-analyzer cargo xml-rs 0.8.19 writer/events/XmlEvent#StartElement#attributes., namespacerust-analyzer cargo xml-rs 0.8.19 writer/events/XmlEvent#StartElement#namespace. } => { |
| 58 | self.emitterrust-analyzer cargo xml-rs 0.8.19 writer/EventWriter#emitter..namespace_stack_mutrust-analyzer cargo xml-rs 0.8.19 writer/emitter/impl#[Emitter]namespace_stack_mut().().push_emptyrust-analyzer cargo xml-rs 0.8.19 namespace/impl#[NamespaceStack]push_empty().().checked_targetrust-analyzer cargo xml-rs 0.8.19 namespace/impl#[NamespaceStack]checked_target().().extendrust-analyzer cargo xml-rs 0.8.19 namespace/impl#[`CheckedTarget<'a>`][`Extend<(&'b str, &'b str)>`]extend().(namespace.as_refrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/impl#[`Cow<'_, T>`][`AsRef<T>`]as_ref().()); |
| 59 | self.emitterrust-analyzer cargo xml-rs 0.8.19 writer/EventWriter#emitter..emit_start_elementrust-analyzer cargo xml-rs 0.8.19 writer/emitter/impl#[Emitter]emit_start_element().(&mut self.sinkrust-analyzer cargo xml-rs 0.8.19 writer/EventWriter#sink., name, &attributes) |
| 60 | } |
| 61 | 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. } => { |
| 62 | let r = self.emitterrust-analyzer cargo xml-rs 0.8.19 writer/EventWriter#emitter..emit_end_elementrust-analyzer cargo xml-rs 0.8.19 writer/emitter/impl#[Emitter]emit_end_element().(&mut self.sinkrust-analyzer cargo xml-rs 0.8.19 writer/EventWriter#sink., name); |
| 63 | self.emitterrust-analyzer cargo xml-rs 0.8.19 writer/EventWriter#emitter..namespace_stack_mutrust-analyzer cargo xml-rs 0.8.19 writer/emitter/impl#[Emitter]namespace_stack_mut().().try_poprust-analyzer cargo xml-rs 0.8.19 namespace/impl#[NamespaceStack]try_pop().(); |
| 64 | r |
| 65 | } |
| 66 | XmlEventrust-analyzer cargo xml-rs 0.8.19 writer/events/XmlEvent#::Commentrust-analyzer cargo xml-rs 0.8.19 writer/events/XmlEvent#Comment#(content) => self.emitterrust-analyzer cargo xml-rs 0.8.19 writer/EventWriter#emitter..emit_commentrust-analyzer cargo xml-rs 0.8.19 writer/emitter/impl#[Emitter]emit_comment().(&mut self.sinkrust-analyzer cargo xml-rs 0.8.19 writer/EventWriter#sink., content), |
| 67 | XmlEventrust-analyzer cargo xml-rs 0.8.19 writer/events/XmlEvent#::CDatarust-analyzer cargo xml-rs 0.8.19 writer/events/XmlEvent#CData#(content) => self.emitterrust-analyzer cargo xml-rs 0.8.19 writer/EventWriter#emitter..emit_cdatarust-analyzer cargo xml-rs 0.8.19 writer/emitter/impl#[Emitter]emit_cdata().(&mut self.sinkrust-analyzer cargo xml-rs 0.8.19 writer/EventWriter#sink., content), |
| 68 | XmlEventrust-analyzer cargo xml-rs 0.8.19 writer/events/XmlEvent#::Charactersrust-analyzer cargo xml-rs 0.8.19 writer/events/XmlEvent#Characters#(content) => self.emitterrust-analyzer cargo xml-rs 0.8.19 writer/EventWriter#emitter..emit_charactersrust-analyzer cargo xml-rs 0.8.19 writer/emitter/impl#[Emitter]emit_characters().(&mut self.sinkrust-analyzer cargo xml-rs 0.8.19 writer/EventWriter#sink., content), |
| 69 | } |
| 70 | } |
| 71 | |
| 72 | /// Returns a mutable reference to the underlying `Writer`. |
| 73 | /// |
| 74 | /// Note that having a reference to the underlying sink makes it very easy to emit invalid XML |
| 75 | /// documents. Use this method with care. Valid use cases for this method include accessing |
| 76 | /// methods like `Write::flush`, which do not emit new data but rather change the state |
| 77 | /// of the stream itself. |
| 78 | pub fn inner_mutrust-analyzer cargo xml-rs 0.8.19 writer/impl#[`EventWriter<W>`]inner_mut().(&mut self) -> &mut W { |
| 79 | &mut self.sinkrust-analyzer cargo xml-rs 0.8.19 writer/EventWriter#sink. |
| 80 | } |
| 81 | |
| 82 | /// Unwraps this `EventWriter`, returning the underlying writer. |
| 83 | /// |
| 84 | /// Note that this is a destructive operation: unwrapping a writer and then wrapping |
| 85 | /// it again with `EventWriter::new()` will create a fresh writer whose state will be |
| 86 | /// blank; for example, accumulated namespaces will be reset. |
| 87 | pub fn into_innerrust-analyzer cargo xml-rs 0.8.19 writer/impl#[`EventWriter<W>`]into_inner().(self) -> W { |
| 88 | self.sinkrust-analyzer cargo xml-rs 0.8.19 writer/EventWriter#sink. |
| 89 | } |
| 90 | } |