Skip to content

Commit

Permalink
Make SimpleTypeDeserializer and SimpleTypeSerializer public
Browse files Browse the repository at this point in the history
  • Loading branch information
Mingun committed Oct 20, 2024
1 parent 1920e03 commit 9218684
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 11 deletions.
1 change: 1 addition & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
### New Features

- [#826]: Implement `From<String>` and `From<Cow<str>>` for `quick_xml::de::Text`.
- [#826]: Make `SimpleTypeDeserializer` and `SimpleTypeSerializer` public.

### Bug Fixes

Expand Down
3 changes: 2 additions & 1 deletion src/de/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2006,8 +2006,9 @@ mod simple_type;
mod text;
mod var;

pub use self::resolver::{EntityResolver, PredefinedEntityResolver};
pub use self::simple_type::SimpleTypeDeserializer;
pub use crate::errors::serialize::DeError;
pub use resolver::{EntityResolver, PredefinedEntityResolver};

use crate::{
de::map::ElementMapAccess,
Expand Down
26 changes: 18 additions & 8 deletions src/de/simple_type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -479,7 +479,7 @@ impl<'de, 'a> SeqAccess<'de> for ListIter<'de, 'a> {
/// - `Option` always deserialized as `Some` using the same deserializer.
/// If attribute or text content is missed, then the deserializer even wouldn't
/// be used, so if it is used, then the value should be;
/// - units (`()`) and unit structs always deserialized successfully;
/// - units (`()`) and unit structs always deserialized successfully, the content is ignored;
/// - newtype structs forwards deserialization to the inner type using the same
/// deserializer;
/// - sequences, tuples and tuple structs are deserialized as `xs:list`s. Only
Expand All @@ -489,9 +489,11 @@ impl<'de, 'a> SeqAccess<'de> for ListIter<'de, 'a> {
/// [`Visitor::visit_borrowed_str`] or [`Visitor::visit_string`]; it is responsibility
/// of the type to return an error if it does not able to process passed data;
/// - enums:
/// - unit variants: just return `()`;
/// - newtype variants: deserialize from [`UnitDeserializer`];
/// - tuple and struct variants: call [`Visitor::visit_unit`];
/// - the variant name is deserialized using the same deserializer;
/// - the content is deserialized using the deserializer that always returns unit (`()`):
/// - unit variants: just return `()`;
/// - newtype variants: deserialize from [`UnitDeserializer`];
/// - tuple and struct variants: call [`Visitor::visit_unit`];
/// - identifiers are deserialized as strings.
///
/// [simple types]: https://www.w3.org/TR/xmlschema11-1/#Simple_Type_Definition
Expand All @@ -509,22 +511,30 @@ pub struct SimpleTypeDeserializer<'de, 'a> {
}

impl<'de, 'a> SimpleTypeDeserializer<'de, 'a> {
/// Creates a deserializer from a value, that possible borrowed from input
/// Creates a deserializer from a value, that possible borrowed from input.
///
/// It is assumed that `text` does not have entities.
pub fn from_text(text: Cow<'de, str>) -> Self {
let content = match text {
Cow::Borrowed(slice) => CowRef::Input(slice.as_bytes()),
Cow::Owned(content) => CowRef::Owned(content.into_bytes()),
};
Self::new(content, false, Decoder::utf8())
}
/// Creates a deserializer from a value, that possible borrowed from input
/// Creates a deserializer from an XML text node, that possible borrowed from input.
///
/// It is assumed that `text` does not have entities.
///
/// This constructor used internally to deserialize from text nodes.
pub fn from_text_content(value: Text<'de>) -> Self {
Self::from_text(value.text)
}

/// Creates a deserializer from a part of value at specified range
/// Creates a deserializer from a part of value at specified range.
///
/// This constructor used internally to deserialize from attribute values.
#[allow(clippy::ptr_arg)]
pub fn from_part(
pub(crate) fn from_part(
value: &'a Cow<'de, [u8]>,
range: Range<usize>,
escaped: bool,
Expand Down
2 changes: 1 addition & 1 deletion src/de/text.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ use std::borrow::Cow;
/// - `Option`:
/// - empty text is deserialized as `None`;
/// - everything else is deserialized as `Some` using the same deserializer;
/// - units (`()`) and unit structs always deserialized successfully;
/// - units (`()`) and unit structs always deserialized successfully, the content is ignored;
/// - newtype structs forwards deserialization to the inner type using the same
/// deserializer;
/// - sequences, tuples and tuple structs are deserialized using [`SimpleTypeDeserializer`]
Expand Down
4 changes: 3 additions & 1 deletion src/se/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,13 +82,15 @@ mod text;
use self::content::ContentSerializer;
use self::element::{ElementSerializer, Map, Struct, Tuple};
use crate::de::TEXT_KEY;
pub use crate::errors::serialize::SeError;
use crate::writer::Indentation;
use serde::ser::{self, Serialize};
use serde::serde_if_integer128;
use std::fmt::Write;
use std::str::from_utf8;

pub use self::simple_type::SimpleTypeSerializer;
pub use crate::errors::serialize::SeError;

/// Serialize struct into a `Write`r.
///
/// Returns the classification of the last written type.
Expand Down

0 comments on commit 9218684

Please sign in to comment.