Struct aws_smithy_xml::encode::XmlWriter

source ·
pub struct XmlWriter<'a> { /* private fields */ }
Expand description

XmlWriter Abstraction

XmlWriter (and friends) make generating an invalid XML document a type error. Nested branches of the Xml document mutable borrow from the root. You cannot continue writing to the root until the nested branch is dropped and dropping the nested branch writes the terminator (e.g. closing element).

The one exception to this rule is names—it is possible to construct an invalid Xml Name. However, names are always known ahead of time and always static, so this would be obvious from the code.

Furthermore, once const panic stabilizes, we’ll be able to make an invalid XmlName a compiler error.

§Examples

use aws_smithy_xml::encode::XmlWriter;
let mut s = String::new();
let mut doc = XmlWriter::new(&mut s);
let mut start_el = doc.start_el("Root")
    .write_ns("http://example.com", None);
let mut start_tag = start_el.finish();
start_tag.data("hello");
start_tag.finish();
assert_eq!(s, "<Root xmlns=\"http://example.com\">hello</Root>");

See tests/handwritten_serializers.rs for more usage examples.

Implementations§

source§

impl<'a> XmlWriter<'a>

source

pub fn new(doc: &'a mut String) -> Self

source§

impl<'a> XmlWriter<'a>

source

pub fn start_el<'b, 'c>(&'c mut self, tag: &'b str) -> ElWriter<'c, 'b>

Auto Trait Implementations§

§

impl<'a> Freeze for XmlWriter<'a>

§

impl<'a> RefUnwindSafe for XmlWriter<'a>

§

impl<'a> Send for XmlWriter<'a>

§

impl<'a> Sync for XmlWriter<'a>

§

impl<'a> Unpin for XmlWriter<'a>

§

impl<'a> !UnwindSafe for XmlWriter<'a>

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

§

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

§

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.