Struct quick_xml::reader::Config

source ·
#[non_exhaustive]
pub struct Config { pub allow_unmatched_ends: bool, pub check_comments: bool, pub check_end_names: bool, pub expand_empty_elements: bool, pub trim_markup_names_in_closing_tags: bool, pub trim_text_start: bool, pub trim_text_end: bool, }
Expand description

A struct that holds a parser configuration.

Current parser configuration can be retrieved by calling Reader::config() and changed by changing properties of the object returned by a call to Reader::config_mut().

Fields (Non-exhaustive)§

This struct is marked as non-exhaustive
Non-exhaustive structs could have additional fields added in future. Therefore, non-exhaustive structs cannot be constructed in external crates using the traditional Struct { .. } syntax; cannot be matched against without a wildcard ..; and struct update syntax will not work.
§allow_unmatched_ends: bool

Whether unmatched closing tag names should be allowed. Unless enabled, in case of a dangling end tag, the Error::IllFormed(UnmatchedEndTag) is returned from read methods.

When set to true, it won’t check if a closing tag has a corresponding opening tag at all. For example, <a></a></b> will be permitted.

Note that the emitted End event will not be modified if this is enabled, ie. it will contain the data of the unmatched end tag.

Note, that setting this to true will lead to additional allocates that needed to store tag name for an End event.

Default: false

§check_comments: bool

Whether comments should be validated. If enabled, in case of invalid comment Error::IllFormed(DoubleHyphenInComment) is returned from read methods.

When set to true, every Comment event will be checked for not containing --, which is not allowed in XML comments. Most of the time we don’t want comments at all so we don’t really care about comment correctness, thus the default value is false to improve performance.

Default: false

§check_end_names: bool

Whether mismatched closing tag names should be detected. If enabled, in case of mismatch the Error::IllFormed(MismatchedEndTag) is returned from read methods.

Note, that start and end tags should match literally, they cannot have different prefixes even if both prefixes resolve to the same namespace. The XML

<outer xmlns="namespace" xmlns:p="namespace">
</p:outer>

is not valid, even though semantically the start tag is the same as the end tag. The reason is that namespaces are an extension of the original XML specification (without namespaces) and it should be backward-compatible.

When set to false, it won’t check if a closing tag matches the corresponding opening tag. For example, <mytag></different_tag> will be permitted.

If the XML is known to be sane (already processed, etc.) this saves extra time.

Note that the emitted End event will not be modified if this is disabled, ie. it will contain the data of the mismatched end tag.

Note, that setting this to true will lead to additional allocates that needed to store tag name for an End event. However if expand_empty_elements is also set, only one additional allocation will be performed that support both these options.

Default: true

§expand_empty_elements: bool

Whether empty elements should be split into an Open and a Close event.

When set to true, all Empty events produced by a self-closing tag like <tag/> are expanded into a Start event followed by an End event. When set to false (the default), those tags are represented by an Empty event instead.

Note, that setting this to true will lead to additional allocates that needed to store tag name for an End event. However if check_end_names is also set, only one additional allocation will be performed that support both these options.

Default: false

§trim_markup_names_in_closing_tags: bool

Whether trailing whitespace after the markup name are trimmed in closing tags </a >.

If true the emitted End event is stripped of trailing whitespace after the markup name.

Note that if set to false and check_end_names is true the comparison of markup names is going to fail erroneously if a closing tag contains trailing whitespace.

Default: true

§trim_text_start: bool

Whether whitespace before character data should be removed.

When set to true, leading whitespace is trimmed in Text events. If after that the event is empty it will not be pushed.

Default: false

WARNING: With this option every text events will be trimmed which is incorrect behavior when text events delimited by comments, processing instructions or CDATA sections. To correctly trim data manually apply BytesText::inplace_trim_start and BytesText::inplace_trim_end only to necessary events.

§trim_text_end: bool

Whether whitespace after character data should be removed.

When set to true, trailing whitespace is trimmed in Text events. If after that the event is empty it will not be pushed.

Default: false

WARNING: With this option every text events will be trimmed which is incorrect behavior when text events delimited by comments, processing instructions or CDATA sections. To correctly trim data manually apply BytesText::inplace_trim_start and BytesText::inplace_trim_end only to necessary events.

Implementations§

source§

impl Config

source

pub fn trim_text(&mut self, trim: bool)

Set both trim_text_start and trim_text_end to the same value.

WARNING: With this option every text events will be trimmed which is incorrect behavior when text events delimited by comments, processing instructions or CDATA sections. To correctly trim data manually apply BytesText::inplace_trim_start and BytesText::inplace_trim_end only to necessary events.

source

pub fn enable_all_checks(&mut self, enable: bool)

Turn on or off all checks for well-formedness. Currently it is that settings:

Trait Implementations§

source§

impl<'arbitrary> Arbitrary<'arbitrary> for Config

source§

fn arbitrary(u: &mut Unstructured<'arbitrary>) -> Result<Self>

Generate an arbitrary value of Self from the given unstructured data. Read more
source§

fn arbitrary_take_rest(u: Unstructured<'arbitrary>) -> Result<Self>

Generate an arbitrary value of Self from the entirety of the given unstructured data. Read more
source§

fn size_hint(depth: usize) -> (usize, Option<usize>)

Get a size hint for how many bytes out of an Unstructured this type needs to construct itself. Read more
source§

impl Clone for Config

source§

fn clone(&self) -> Config

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 Debug for Config

source§

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

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

impl Default for Config

source§

fn default() -> Self

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

impl<'de> Deserialize<'de> for Config

source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
source§

impl PartialEq for Config

source§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

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

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl Serialize for Config

source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
source§

impl Eq for Config

source§

impl StructuralPartialEq for Config

Auto Trait Implementations§

§

impl Freeze for Config

§

impl RefUnwindSafe for Config

§

impl Send for Config

§

impl Sync for Config

§

impl Unpin for Config

§

impl UnwindSafe for Config

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> CloneToUninit for T
where T: Clone,

source§

unsafe fn clone_to_uninit(&self, dst: *mut T)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. 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,

source§

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

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.
source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,