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

Error in derive(YaDeserialize): wrong number of type arguments: expected 1, found 0 #3

Closed
Boscop opened this issue May 13, 2018 · 8 comments

Comments

@Boscop
Copy link

Boscop commented May 13, 2018

I'm getting an error
image

for the following:

#[derive(Default, Debug, Clone, PartialEq, YaSerialize, YaDeserialize)]
#[yaserde(root = "layout")]
pub struct Layout {
	#[yaserde(attribute)]
	pub version: u32,
	#[yaserde(attribute)]
	pub mode: u32,
	#[yaserde(attribute)]
	pub w: u32,
	#[yaserde(attribute)]
	pub h: u32,
	#[yaserde(attribute)]
	pub orientation: Orientation,
	pub tabpage: Tabpage,
}

#[derive(Default, Debug, Clone, PartialEq, YaSerialize, YaDeserialize)]
pub struct Tabpage {
	#[yaserde(attribute)]
	pub name: String,
	#[yaserde(attribute)]
	pub scalef: f32,
	#[yaserde(attribute)]
	pub scalet: f32,
	#[yaserde(attribute)]
	pub li_t: String,
	#[yaserde(attribute)]
	pub li_c: String,
	#[yaserde(attribute)]
	pub li_s: String,
	#[yaserde(attribute)]
	pub li_o: String,
	#[yaserde(attribute)]
	pub li_b: String,
	#[yaserde(attribute)]
	pub la_t: String,
	#[yaserde(attribute)]
	pub la_c: String,
	#[yaserde(attribute)]
	pub la_s: String,
	#[yaserde(attribute)]
	pub la_o: String,
	#[yaserde(attribute)]
	pub la_b: String,
	pub control: Vec<Control>,
}

#[derive(Default, Debug, Clone, PartialEq, YaSerialize, YaDeserialize)]
pub struct Control {
	#[yaserde(attribute)]
	pub name: String,
	#[yaserde(attribute)]
	pub x: u32,
	#[yaserde(attribute)]
	pub y: u32,
	#[yaserde(attribute)]
	pub w: u32,
	#[yaserde(attribute)]
	pub h: u32,
	#[yaserde(attribute)]
	pub color: String,
	#[yaserde(attribute)]
	pub scalef: f32,
	#[yaserde(attribute)]
	pub scalet: f32,
	#[yaserde(attribute)]
	pub local_off: Option<bool>,
	#[yaserde(attribute)]
	pub sp: Option<String>,
	#[yaserde(attribute)]
	pub sr: Option<String>,
	pub midi: Option<Midi>,
	#[yaserde(attribute)]
	pub response: Option<Response>,
	#[yaserde(attribute)]
	pub inverted: Option<bool>,
	#[yaserde(attribute)]
	pub centered: Option<bool>,
	#[yaserde(attribute)]
	pub norollover: Option<bool>,
}

#[derive(Debug, Clone, PartialEq, YaSerialize, YaDeserialize)]
pub enum Response { absolute, relative }

#[derive(Debug, Clone, PartialEq, YaSerialize, YaDeserialize)]
pub enum Orientation { vertical, horizontal }

#[derive(Default, Debug, Clone, PartialEq, YaSerialize, YaDeserialize)]
pub struct Midi {
	#[yaserde(attribute)]
	pub var: String,
	#[yaserde(attribute)]
	#[yaserde(rename = "type")]
	pub typ: String,
	#[yaserde(attribute)]
	pub channel: u8,
	#[yaserde(attribute)]
	pub data1: u8,
	#[yaserde(attribute)]
	pub data2f: u8,
	#[yaserde(attribute)]
	pub data2t: u8,
	#[yaserde(attribute)]
	pub sysex: String,
}

wrong number of type arguments: expected 1, found 0
expected 1 type argument


Btw, my goal is to serialize xml docs in this format:

<?xml version="1.0" encoding="UTF-8"?>
<layout version="16" mode="3" w="460" h="736" orientation="vertical">
    <tabpage name="MQ==" scalef="0.0" scalet="1.0" li_t="" li_c="gray" li_s="14" li_o="false" li_b="false" la_t="" la_c="gray" la_s="14" la_o="false" la_b="false">
        <control name="cHVzaDI1" x="114" y="680" w="45" h="45" color="red" scalef="0.0" scalet="1.0" type="push" local_off="false" sp="true" sr="true">
            <midi var="x" type="1" channel="1" data1="25" data2f="0" data2t="127" sysex="" />
        </control>
        <control name="cm90YXJ5MA==" x="14" y="569" w="100" h="100" color="red" scalef="0.0" scalet="1.0" type="rotaryh" response="absolute" inverted="false" centered="false" norollover="true">
            <midi var="x" type="0" channel="1" data1="0" data2f="0" data2t="127" sysex="" />
        </control>
        <control name="ZmFkZXIz" x="0" y="151" w="120" h="40" color="blue" scalef="0.0" scalet="1.0" type="faderh" response="relative" inverted="false" centered="false" />
    </tabpage>
</layout>

How can I do this with yaserde? :)

@MarcAntoine-Arnaud
Copy link
Contributor

Starting to looks cool.

Just a little remark:

#[yaserde(attribute)]
#[yaserde(rename = "type")]
pub typ: String,

can be a little more simple using:

#[yaserde(attribute, rename="type")]
pub typ: String,

Right now conversion to any type are not supported. So attribute value to u32, f64 will not work.
Option is also in the roadmap.
Maybe your error is related to these issues.

@Boscop
Copy link
Author

Boscop commented May 13, 2018

Thanks for the quick reply :)

I tried using only String but:
image

#[derive(Default, Debug, Clone, PartialEq, YaSerialize, YaDeserialize)]
#[yaserde(root = "layout")]
pub struct Layout {
	#[yaserde(attribute)]
	pub version: String,
	#[yaserde(attribute)]
	pub mode: String,
	#[yaserde(attribute)]
	pub w: String,
	#[yaserde(attribute)]
	pub h: String,
	#[yaserde(attribute)]
	pub orientation: String,
	pub tabpage: Tabpage,
}

#[derive(Default, Debug, Clone, PartialEq, YaSerialize, YaDeserialize)]
pub struct Tabpage {
	#[yaserde(attribute)]
	pub name: String,
	#[yaserde(attribute)]
	pub scalef: String,
	#[yaserde(attribute)]
	pub scalet: String,
	#[yaserde(attribute)]
	pub li_t: String,
	#[yaserde(attribute)]
	pub li_c: String,
	#[yaserde(attribute)]
	pub li_s: String,
	#[yaserde(attribute)]
	pub li_o: String,
	#[yaserde(attribute)]
	pub li_b: String,
	#[yaserde(attribute)]
	pub la_t: String,
	#[yaserde(attribute)]
	pub la_c: String,
	#[yaserde(attribute)]
	pub la_s: String,
	#[yaserde(attribute)]
	pub la_o: String,
	#[yaserde(attribute)]
	pub la_b: String,
	pub control: Control,
}

#[derive(Default, Debug, Clone, PartialEq, YaSerialize, YaDeserialize)]
pub struct Control {
	#[yaserde(attribute)]
	pub name: String,
	#[yaserde(attribute)]
	pub x: String,
	#[yaserde(attribute)]
	pub y: String,
	#[yaserde(attribute)]
	pub w: String,
	#[yaserde(attribute)]
	pub h: String,
	#[yaserde(attribute)]
	pub color: String,
	#[yaserde(attribute)]
	pub scalef: String,
	#[yaserde(attribute)]
	pub scalet: String,
	#[yaserde(attribute)]
	pub local_off: String,
	#[yaserde(attribute)]
	pub sp: String,
	#[yaserde(attribute)]
	pub sr: String,
	pub midi: Midi,
	#[yaserde(attribute)]
	pub response: String,
	#[yaserde(attribute)]
	pub inverted: String,
	#[yaserde(attribute)]
	pub centered: String,
	#[yaserde(attribute)]
	pub norollover: String,
}

#[derive(Default, Debug, Clone, PartialEq, YaSerialize, YaDeserialize)]
pub struct Midi {
	#[yaserde(attribute)]
	pub var: String,
	#[yaserde(attribute, rename="type")]
	pub typ: String,
	#[yaserde(attribute)]
	pub channel: String,
	#[yaserde(attribute)]
	pub data1: String,
	#[yaserde(attribute)]
	pub data2f: String,
	#[yaserde(attribute)]
	pub data2t: String,
	#[yaserde(attribute)]
	pub sysex: String,
}

@MarcAntoine-Arnaud
Copy link
Contributor

Okay I found the issue !

Name name is used internally, with an OwnedName type. So the conflit comes from here.
So for now use an another name for the field and use the rename like:

#[yaserde(attribute, rename="name")]
pub named: String,

So it will works ;-)

@MarcAntoine-Arnaud
Copy link
Contributor

Does it works ?
I'm working on type support (numbers etc.), it will be released soon !

@Boscop
Copy link
Author

Boscop commented May 15, 2018

Thanks!
I realized I don't really need to deserialize (for now), only serialize, so I removed the Deserialize derive.
But I think it would have worked with named..

Btw, I'm looking forward to Option support so that None attribs won't be written (right now I have to use String so they get serialized as empty strings) :)

(The software that reads in the xml files I generate seems to ignore empty string attribs, so it works out, for now..)

@MarcAntoine-Arnaud
Copy link
Contributor

Okay cool, do you have time to improve and provide a support of Option ?
It's the right way for that, of course.

@Boscop
Copy link
Author

Boscop commented May 15, 2018

I'm very busy until the end of this month (and have to prepare some stuff for RustFest), but after that I'll have some time..

@MarcAntoine-Arnaud
Copy link
Contributor

Hi @Boscop,
I updated the library to support Option, and all basic types.
Tell me if it's works and if I can close this Issue.

(I have also updated xml-rs to 0.8.0, just in case)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants