Closed bilelmoussaoui closed 4 months ago
@bilelmoussaoui Hey! Thank you for you report and sorry for the poor documents.
Since here Version
is an attribute so it should be a XmlValue. (I think) All of the builtin types have been implemented, so you can use it directly.
#[test]
fn test_issue32() {
type Version = String;
#[derive(Debug, XmlDeserialize)]
#[xmlserde(root = b"repository")]
pub struct Repository {
#[xmlserde(name = b"version", ty = "attr")]
version: Version,
}
let xml = r#"<repository xmlns="http://www.gtk.org/introspection/core/1.0" xmlns:c="http://www.gtk.org/introspection/c/1.0" xmlns:glib="http://www.gtk.org/introspection/glib/1.0" version="1.2"></repository>"#;
let repo = xml_deserialize_from_str::<Repository>(&xml).unwrap();
assert_eq!(repo.version, "1.2");
}
What you are using here is an alias, type Version = String
and not a struct Version(String);
, can it work in this case?
Thanks for the quick reply
@bilelmoussaoui Oh yes. Now the struct or enum is not designed to be used in attributes (and I think this is an effective way to keep the process of serializing/deserializing understandable). So no available proc macro for it. If you still want to do so, then you have to implement the XmlValue
for your own structs
Oh I see! Yes, implementing the trait makes the error go away and everything works flawlessly. Should I go ahead and close this issue or do you want to keep it open for either documentation purposes or to improve the reported error message from the XmlDeserialize macro?
I am trying to parse an xml file that has various
version
attributes, so I want to create a wrapper structpub struct Version(String);
and use that instead of just an alias which would work fine.Given the following xml
The following code should work
Instead the code fails to compile with