pub struct Element<T> {
    pub name: T,
    pub text: Option<T>,
    /* private fields */
}
Expand description

represents the structure and characteristics of an XML element

Fields§

§name: T§text: Option<T>

Implementations§

source§

impl<T: PartialEq + Display + Debug> Element<T>

source

pub fn new(name: T, attributes: Vec<T>) -> Element<T>

source

pub fn formatted_name(&self) -> String

format the name of the element to be properly represented as a Rust struct

source

pub fn standalone(&self) -> bool

return true if this tag always appears only 0 or 1 times within it’s parent element return false if this tag appears at least once more than 1 times within it’s parent element

source

pub fn set_multiple(&mut self)

call this function if this element appears more than once inside a parent element

source

pub fn count(&self) -> u32

return how often the element is present inside the current parent element, only used during parsing an XML document

source

pub fn increment(&mut self)

increase the counter by one, only used during parsing an XML document

source

pub fn merge_attr(self, attributes: Vec<Necessity<T>>) -> Element<T>

merge the given list of attributes into the list if the element’s attributes attributes that not appear in both lists are marked as optional

Example

use xml_schema_generator::Element;
use xml_schema_generator::Necessity;

let mut root = Element::new("car", vec!["name", "colour"]);
root = root.merge_attr(vec![Necessity::Mandatory("name"), Necessity::Mandatory("type")]);
source

pub fn add_unique_child(&mut self, child: Element<T>)

add a new child element to this element, if it does not exist yet

source

pub fn set_child_optional(&mut self, name: &T)

find a child element with the given name, mark it as optional if found

source

pub fn get_child(&self, name: &T) -> Option<&Necessity<Element<T>>>

find a child element by name and return a reference to it if found

source

pub fn get_child_mut(&mut self, name: &T) -> Option<&mut Necessity<Element<T>>>

find a child element by name and return it as mutable reference if found

source

pub fn remove_child(&mut self, name: &T) -> Option<Necessity<Element<T>>>

find a child element by name, remove it from this element and return it

source

pub fn children(&self) -> &Vec<Necessity<Element<T>>>

return a reference to the list of all child elements

source§

impl<T: PartialEq + Display + Debug + Clone> Element<T>

source

pub fn to_serde_struct(&self, options: &Options) -> String

generate a String representing this element and all children elements recursivly as series of Rust structs those struct can be used to (de)serialize an XML document

Trait Implementations§

source§

impl<T: Clone> Clone for Element<T>

source§

fn clone(&self) -> Element<T>

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl<T: Debug> Debug for Element<T>

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl<T: PartialEq> PartialEq for Element<T>

source§

fn eq(&self, other: &Self) -> bool

return true if two elements share the same name should only be used to compare two elements that share the same parent element

1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.

Auto Trait Implementations§

§

impl<T> RefUnwindSafe for Element<T>
where T: RefUnwindSafe,

§

impl<T> Send for Element<T>
where T: Send,

§

impl<T> Sync for Element<T>
where T: Sync,

§

impl<T> Unpin for Element<T>
where T: Unpin,

§

impl<T> UnwindSafe for Element<T>
where T: 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> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.