Writer

Struct Writer 

Source
pub struct Writer { /* private fields */ }
Expand description

Write a document, specifying some formatting options

For example, the default is to use single-quotes for attributes. To use double quotes for attributes, you need to use set_single_quotes(false).

use sxd_document::{Package, writer::Writer};

// Create a new document
let p = Package::new();
let doc = p.as_document();
let el = doc.create_element("hello");
el.set_attribute_value("a", "b");
doc.root().append_child(el);

// Format the document as bytes
let mut output = Vec::new();
Writer::new().set_single_quotes(false).format_document(&doc, &mut output);

// Check that the output is correct
let output_string = String::from_utf8(output).unwrap();
assert_eq!(output_string, r#"<?xml version="1.0"?><hello a="b"/>"#);

Implementations§

Source§

impl Writer

Source

pub fn new() -> Self

Create a new Writer with default settings.

Source

pub fn set_single_quotes(self, single_quotes: bool) -> Self

Set whether single quotes should be used for writing a document.

Source

pub fn set_write_encoding(self, write_encoding: bool) -> Self

Set whether the encoding should be specified in the output document header.

Source§

impl Writer

Source

pub fn format_document<'d, W>( &self, doc: &'d Document<'d>, writer: &mut W, ) -> Result<()>
where W: Write + ?Sized,

Formats a document into a Write

Trait Implementations§

Source§

impl Default for Writer

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

§

impl Freeze for Writer

§

impl RefUnwindSafe for Writer

§

impl Send for Writer

§

impl Sync for Writer

§

impl Unpin for Writer

§

impl UnwindSafe for Writer

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.