Struct XMLWriter

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

Helper struct used to manage the XML serialization of Items.

When the XMLWriter is first created, the XML header is immediately written. When the XMLWriter is dropped, the XML footer is written and the Write is flushed.

Any errors produced by writing the footer are silently ignored. The close() method can be used to return any such error.

Implementations§

Source§

impl<W: Write> XMLWriter<W>

Source

pub fn new(w: W) -> Result<XMLWriter<W>>

Returns a new XMLWriter that writes to the given Write.

The XML header is written immediately.

Source

pub fn write_item(&mut self, item: &Item<'_>) -> Result<()>

Writes an Item to the underlying Write.

If a previous write produced an error, any subsequent write will do nothing and return the same error. This is because the previous write may have partially completed, and attempting to write any more data will be unlikely to work properly.

Source

pub fn close(self) -> Result<W>

Consumes the XMLWriter and writes the XML footer.

This method can be used to get any error resulting from writing the footer. If this method is not used, the footer will be written when the XMLWriter is dropped and any error will be silently ignored.

As with write_item(), if a previous invocation of write_item() returned an error, close() will return the same error without attempting to write the XML footer.

When this method is used, the XML footer is written, but the Write is not flushed. When the XMLWriter is dropped without calling close(), the Write is flushed after the footer is written.

Trait Implementations§

Source§

impl<W: Write> Drop for XMLWriter<W>

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more

Auto Trait Implementations§

§

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

§

impl<W> !RefUnwindSafe for XMLWriter<W>

§

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

§

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

§

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

§

impl<W> !UnwindSafe for XMLWriter<W>

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.

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, 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.