Writer

Struct Writer 

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

An XML writer.

Implementations§

Source§

impl<W: Write> Writer<W>

Source

pub fn new(writer: W) -> Self

Creates a new Writer that will write into writer.

Source

pub fn with_options(writer: W, options: Options) -> Self

Creates a new Writer that will write into writer with the specified options.

Source

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

Writes a start tag with the specified prefix and name into the writer.

§Errors

Returns an error if the prefix or name is invalid or an underlying I/O error occurs.

Source

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

Writes an empty tag with the specified prefix and name into the writer.

§Errors

Returns an error if the prefix or name is invalid or an underlying I/O error occurs.

Source

pub fn write_raw_attribute( &mut self, name: &str, quote: AttributeQuote, value: &str, ) -> Result<(), Error>

Writes an attribute with the specified prefix and name into the writer.

The attribute will use the double quote as the quote character. Does not escape the value but will return an error if is improperly escaped.

Must only be called in the context of a start tag, i.e. after a successful Self::write_start, Self::write_empty, Self::write_raw_attribute, or Self::write_attribute.

§Errors

Returns an error if the name or value is invalid or an underlying I/O error occurs.

Source

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

Writes an attribute with the specified prefix and name into the writer.

The attribute will use the double quote as the quote character.

Must only be called in the context of a start tag, i.e. after a successful Self::write_start, Self::write_empty, Self::write_raw_attribute, or Self::write_attribute.

§Errors

Returns an error if the name is invalid or an underlying I/O error occurs.

Source

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

Writes an end tag with the specified prefix and name into the writer.

§Errors

Returns an error if the prefix or name is invalid or an underlying I/O error occurs.

Source

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

Writes text content into the writer.

§Errors

Returns an error if the content is improperly escaped or contains a null byte or an underlying I/O error occurs.

Source

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

Writes text content into the writer.

§Notes

Currently this function does not check for null bytes in the string. This may change in a future release.

§Errors

Returns an error if an underlying I/O error occurs.

Source

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

Writes cdata into the writer.

§Notes

Currently this function does not check for null bytes in the string. This may change in a future release.

§Errors

Returns an error if the string contains ]]> or an underlying I/O error occurs.

Source

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

Writes a comment into the writer.

§Notes

Currently this function does not check for null bytes in the string. This may change in a future release.

§Errors

Returns an error if the string contains --> or an underlying I/O error occurs.

Source

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

Writes a comment into the writer.

§Notes

Currently this function does not check for null bytes in the string. This may change in a future release.

§Errors

Returns an error if an underlying I/O error occurs.

Source

pub fn write_attribute_event( &mut self, attr: &AttributeEvent<'_>, ) -> Result<(), Error>

Writes a comment into the writer.

§Notes

Currently this function does not check for null bytes in the string. This may change in a future release.

§Errors

Returns an error if an underlying I/O error occurs.

Source

pub fn write_event(&mut self, event: &Event<'_>) -> Result<(), Error>

Writes an event into the writer.

§Errors

Returns an error if an underlying I/O error occurs.

Source

pub fn inner_ref(&self) -> &W

Returns a reference to the underlying writer.

Source

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

Returns a mutable reference to the underlying writer.

Source

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

If the writer is currently in a start tag context, ensures that the tag is closed, and then returns the underlying writer.

§Errors

Returns an error if an underlying I/O error occurred.

Source

pub fn flush(&mut self) -> Result<()>

If the writer is currently in a start tag context, ensures that the tag is closed, and then flushes the underlying writer.

§Errors

Returns an error if an underlying I/O error occurred.

Auto Trait Implementations§

§

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

§

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

§

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

§

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

§

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

§

impl<W> UnwindSafe for Writer<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.

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.