-
Notifications
You must be signed in to change notification settings - Fork 60
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
Tuple struct causes proc-macro panic #191
Comments
Same, still happening, relevant part of backtrace: 18: 0x79f818cc9b93 - yaserde_derive::common::field::YaSerdeField::renamed_label_without_namespace::h389779400a5143d4
19: 0x79f818cc9f6a - yaserde_derive::common::field::YaSerdeField::get_visitor_ident::h68e638260011394b
20: 0x79f818cb066b - yaserde_derive::de::expand_struct::parse::{{closure}}::{{closure}}::h717fce7aebfe5022 |
I had the same issue. use std::fmt::{Debug, Display};
use std::io::{Read, Write};
use xml::attribute::OwnedAttribute;
use xml::namespace::Namespace;
use xml::reader::XmlEvent;
use yaserde::de::Deserializer;
use yaserde::ser::Serializer;
use yaserde::{YaDeserialize, YaSerialize};
#[derive(PartialEq, Debug, Default)]
pub struct TestNumber(pub u32);
impl YaSerialize for TestNumber {
fn serialize<W: Write>(&self, writer: &mut Serializer<W>) -> Result<(), String> {
// if serializing an attribute, we don't have a start and end element
let mut start_written = false;
if let Some(start_event_name) = writer.get_start_event_name() {
writer
.write(xml::writer::XmlEvent::start_element(start_event_name.as_str()))
.map_err(|e| e.to_string())?;
start_written = true;
}
writer.write(xml::writer::XmlEvent::characters(self.0.to_string().as_str()))
.map_err(|e| e.to_string())?;
if start_written {
writer
.write(xml::writer::XmlEvent::end_element())
.map_err(|e| e.to_string())?;
}
Ok(())
}
fn serialize_attributes(&self, attributes: Vec<OwnedAttribute>, namespace: Namespace) -> Result<(Vec<OwnedAttribute>, Namespace), String> {
Ok((attributes, namespace))
}
}
impl YaDeserialize for TestNumber {
fn deserialize<R: Read>(reader: &mut Deserializer<R>) -> Result<Self, String> {
let mut result = Self::default();
match reader.next_event()? {
XmlEvent::Characters(text) => result.0 = text.parse::<u32>().map_err(|e| e.to_string())?,
_ => return Err("expected only characters".to_string())
}
Ok(result)
}
}
#[derive(PartialEq, Debug, Default)]
pub struct TestTestNumber(pub TestNumber);
impl YaSerialize for TestTestNumber {
fn serialize<W: Write>(&self, writer: &mut Serializer<W>) -> Result<(), String> {
self.0.serialize(writer)
}
fn serialize_attributes(&self, attributes: Vec<OwnedAttribute>, namespace: Namespace) -> Result<(Vec<OwnedAttribute>, Namespace), String> {
Ok((attributes, namespace))
}
}
impl YaDeserialize for TestTestNumber {
fn deserialize<R: Read>(reader: &mut Deserializer<R>) -> Result<Self, String> {
Ok(TestTestNumber(TestNumber::deserialize(reader)?))
}
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
causes:
The text was updated successfully, but these errors were encountered: