XmlStreamWriter

Struct XmlStreamWriter 

Source
pub struct XmlStreamWriter<W: Write> { /* private fields */ }
Expand description

Direct XML event writer with bounded output and namespace/state validation.

Implementations§

Source§

impl<W: Write> XmlStreamWriter<W>

Source

pub fn new(inner: W) -> Result<Self, Error>

Creates a writer with default bounded output options.

§Errors

Returns an error if initial writer setup or declaration output fails.

Source

pub fn with_options(inner: W, options: XmlWriteOptions) -> Result<Self, Error>

Creates a writer with explicit output options.

§Errors

Returns an error when any option limit is zero or the optional XML declaration cannot be written within the configured output bound.

Source

pub fn start_element<'a, I, A>( &mut self, name: &str, attributes: I, ) -> Result<(), Error>
where I: IntoIterator<Item = A>, A: Into<XmlWriteAttribute<'a>>,

Starts a non-empty element with attributes.

§Errors

Returns an error for invalid names, attributes, namespace bindings, document state, depth or attribute limits, output overflow, or sink I/O failure.

Source

pub fn empty_element<'a, I, A>( &mut self, name: &str, attributes: I, ) -> Result<(), Error>
where I: IntoIterator<Item = A>, A: Into<XmlWriteAttribute<'a>>,

Writes an empty element with attributes.

§Errors

Returns an error for invalid names, attributes, namespace bindings, document state, depth or attribute limits, output overflow, or sink I/O failure.

Source

pub fn start(&mut self, name: &str) -> Result<(), Error>

Starts a non-empty element without attributes.

§Errors

Returns any validation, state, safety-limit, or I/O error from Self::start_element.

Source

pub fn empty(&mut self, name: &str) -> Result<(), Error>

Writes an empty element without attributes.

§Errors

Returns any validation, state, safety-limit, or I/O error from Self::empty_element.

Source

pub fn end_element(&mut self) -> Result<(), Error>

Ends the innermost open element.

§Errors

Returns an error when no element is open, the output bound is exceeded, or the sink fails.

Source

pub fn text(&mut self, value: &str) -> Result<(), Error>

Writes escaped XML character data.

§Errors

Returns an error for invalid XML characters, non-whitespace text outside the root, output overflow, or sink I/O failure.

Source

pub fn cdata(&mut self, value: &str) -> Result<(), Error>

Writes one CDATA section.

§Errors

Returns an error for invalid XML characters, CDATA outside the root, a ]]> terminator in the value, output overflow, or sink I/O failure.

Source

pub fn comment(&mut self, value: &str) -> Result<(), Error>

Writes one XML comment.

§Errors

Returns an error for invalid XML characters or hyphen sequences, output overflow, or sink I/O failure.

Source

pub fn processing_instruction( &mut self, target: &str, content: Option<&str>, ) -> Result<(), Error>

Writes one processing instruction.

§Errors

Returns an error for an invalid or reserved target, invalid content characters or ?> sequence, output overflow, or sink I/O failure.

Source

pub fn validated_subtree(&mut self, subtree: &ValidatedXml) -> Result<(), Error>

Embeds one already validated, self-contained XML root below the current element.

§Errors

Returns an error when no parent element is open, the subtree would inherit an incompatible default namespace, exceeds writer depth or attribute limits, exceeds the output bound, or the sink fails.

Source

pub fn written_bytes(&self) -> usize

Source

pub fn get_ref(&self) -> &W

Source

pub fn get_mut(&mut self) -> &mut W

Returns a mutable reference to the output sink without ending the XML document.

This is intended for sinks that expose already-written bounded chunks while the writer retains ownership of XML namespace and document state. Mutating the sink must not change or discard bytes that it has previously reported as successfully written.

Source

pub fn finish(self) -> Result<W, Error>

Finishes a complete XML document and returns its output sink.

§Errors

Returns an error when elements remain open, no complete root was written, the output limit was exceeded, or flushing the sink fails.

Auto Trait Implementations§

§

impl<W> Freeze for XmlStreamWriter<W>
where W: Freeze,

§

impl<W> RefUnwindSafe for XmlStreamWriter<W>
where W: RefUnwindSafe,

§

impl<W> Send for XmlStreamWriter<W>
where W: Send,

§

impl<W> Sync for XmlStreamWriter<W>
where W: Sync,

§

impl<W> Unpin for XmlStreamWriter<W>
where W: Unpin,

§

impl<W> UnwindSafe for XmlStreamWriter<W>
where W: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more