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

Question: name as attribute with serde #715

Open
WesleyAC opened this issue Feb 22, 2024 · 1 comment
Open

Question: name as attribute with serde #715

WesleyAC opened this issue Feb 22, 2024 · 1 comment
Labels
question serde Issues related to mapping from Rust types to XML

Comments

@WesleyAC
Copy link

I have a struct like:

struct Foo {
    one: String,
    two: String,
}

and I want XML like:

<foo>
    <item name="one">value of string 1</item>
    <item name="two">value of string 2</item>
</foo>

I don't see a easy way to do this kind of thing with quick-xml's serde option — my experiments have been using PhantomData to create a Item<K, V> type where the K is a PhantomData<K> with a custom trait to hold the name, and then I use the serde with attribute, but that feels quite messy and annoying. Is there a easy way to represent this? (I wouldn't choose to use XML like this, but the API I'm using does, unfortunately...)

@Mingun Mingun added question serde Issues related to mapping from Rust types to XML labels Feb 23, 2024
@Mingun Mingun closed this as completed Feb 23, 2024
@Mingun Mingun reopened this Feb 23, 2024
@Mingun
Copy link
Collaborator

Mingun commented Feb 23, 2024

There is no built-in mappings for such transformations. Probably, your way to do that is the right approach. If you post your solution here, maybe we could help you to find the ways to optimize it.

Here is mine variant.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question serde Issues related to mapping from Rust types to XML
Projects
None yet
Development

No branches or pull requests

2 participants