Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for XML Schema xs:list type #376

Closed
wants to merge 13 commits into from
Closed

Conversation

Mingun
Copy link
Collaborator

@Mingun Mingun commented Mar 23, 2022

This PR allows deserializing Vec and other sequences from space-separated lists, as defined by XML Schema specification. So now this is possible:
Deserialize

struct AnyName {
  // Will contain vec!["first", "second", "third"]
  attribute: Vec<String>,
}

from

<any-tag attribute="first second third">

This PR is based on #374, because before parsing text/CDATA content I will need to fix CDATA handling. It also cancels change in the bytes deserializing: now it is again possible to get a raw content of the parsed buffer using deserializing into Vec<u8> / &[u8]. This is not much useful in my opinion, although, so I put a TODO to look at this later.

Mingun and others added 5 commits February 5, 2022 22:08
Now debug representation is readable
failures:
    de::tests::trivial::struct_::cdata::byte_buf
    de::tests::trivial::struct_::cdata::char_
    de::tests::trivial::struct_::cdata::f32_
    de::tests::trivial::struct_::cdata::f64_
    de::tests::trivial::struct_::cdata::false_
    de::tests::trivial::struct_::cdata::i128_
    de::tests::trivial::struct_::cdata::i16_
    de::tests::trivial::struct_::cdata::i32_
    de::tests::trivial::struct_::cdata::i64_
    de::tests::trivial::struct_::cdata::i8_
    de::tests::trivial::struct_::cdata::isize_
    de::tests::trivial::struct_::cdata::string
    de::tests::trivial::struct_::cdata::true_
    de::tests::trivial::struct_::cdata::u128_
    de::tests::trivial::struct_::cdata::u16_
    de::tests::trivial::struct_::cdata::u32_
    de::tests::trivial::struct_::cdata::u64_
    de::tests::trivial::struct_::cdata::u8_
    de::tests::trivial::struct_::cdata::usize_
    de::tests::trivial::struct_::text::byte_buf
… trivial tests

failures:
    de::tests::trivial::struct_::text::byte_buf
    de::tests::trivial::struct_::cdata::byte_buf
Comment on lines 178 to +187
State::Attribute => {
let decoder = self.de.reader.decoder();
match self.next_attr()? {
Some(a) => seed.deserialize(EscapedDeserializer::new(a.value, decoder, true)),
Some(a) => {
//FIXME: we have to clone value because of wrong lifetimes on `a`
// It should be bound to the input lifetime, but it instead bound
// to a deserializer lifetime
let value: Vec<_> = a.value.into_owned();
seed.deserialize(SimpleTypeDeserializer::new(value.into(), true, decoder))
}
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a temporary solution. I'll remove this clone in next PRs, when I figure out how to do that. In any case, struct / map deserialization should be reviewed to match expectations that I documenting in #369

@Mingun Mingun added enhancement serde Issues related to mapping from Rust types to XML labels May 21, 2022
@dralley dralley self-requested a review May 21, 2022 22:40
@@ -35,9 +36,15 @@ impl<'de> Deserialize<'de> for ByteBuf {
}
}

impl fmt::Debug for ByteBuf {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write_byte_string(f, &self.0)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

write_byte_string could use some documentation

@@ -36,6 +36,8 @@ where
let decoder = self.de.reader.decoder();
let de = match self.de.peek()? {
DeEvent::Text(t) => EscapedDeserializer::new(Cow::Borrowed(t), decoder, true),
// Escape sequences does not processed inside CDATA section
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// Escape sequences does not processed inside CDATA section
// Escape sequences are not processed inside CDATA section

@Mingun
Copy link
Collaborator Author

Mingun commented Jun 5, 2022

GitHub thinks that this PR coming from https://github.com/Mingun/fast-xml/tree/xs-list repo and I cannot change that, so I'll close it and make a new PR

@Mingun Mingun closed this Jun 5, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement serde Issues related to mapping from Rust types to XML
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants