Struct ElementBuilder

Source
pub struct ElementBuilder<'a> { /* private fields */ }
Expand description

An easy way to build a new element by chaining methods to add properties.

Call Element::build() to start building. To finish building, either call .finish() or .push_to(parent) which returns Element.

§Examples

use xml_doc::{Document, Element, Node};

let mut doc = Document::new();

let root = Element::build(&mut doc, "root")
    .attribute("id", "main")
    .attribute("class", "main")
    .finish();
doc.push_root_node(root.as_node());

let name = Element::build(&mut doc, "name")
    .text_content("No Name")
    .push_to(root);

/* Equivalent xml:
  <root id="main" class="main">
    <name>No Name</name>
  </root>
*/

Implementations§

Source§

impl<'a> ElementBuilder<'a>

Source

pub fn prefix<S: Into<String>>(self, prefix: S) -> Self

Removes previous prefix if it exists, and attach new prefix.

Source

pub fn attribute<S, T>(self, name: S, value: T) -> Self
where S: Into<String>, T: Into<String>,

Source

pub fn namespace_decl<S, T>(self, prefix: S, namespace: T) -> Self
where S: Into<String>, T: Into<String>,

Source

pub fn text_content<S: Into<String>>(self, text: S) -> Self

Source

pub fn finish(self) -> Element

Source

pub fn push_to(self, parent: Element) -> Element

Push this element to the parent’s children.

Auto Trait Implementations§

§

impl<'a> Freeze for ElementBuilder<'a>

§

impl<'a> RefUnwindSafe for ElementBuilder<'a>

§

impl<'a> Send for ElementBuilder<'a>

§

impl<'a> Sync for ElementBuilder<'a>

§

impl<'a> Unpin for ElementBuilder<'a>

§

impl<'a> !UnwindSafe for ElementBuilder<'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>,

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.