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

with_prefix attribute #759

Closed
xamgore opened this issue Jun 27, 2024 · 1 comment
Closed

with_prefix attribute #759

xamgore opened this issue Jun 27, 2024 · 1 comment

Comments

@xamgore
Copy link

xamgore commented Jun 27, 2024

Hi, I am wondering, is it technically possible to omit separate macro-calls (as in #9) and inline them into the list of attributes?

#[derive(Serialize, Deserialize)]
struct Match {
    #[serde(flatten, with_prefix = "player1_")]
    player1: Player,
    #[serde(flatten, with_prefix = "player2_")]
    player2: Player,
}

#[derive(Serialize, Deserialize)]
struct Player {
    name: String,
    votes: u64,
}

I'm in the middle of writing a docx-template library, that takes user data and distributes it to a document's {placeholders}. Things get worse, when you have a lot of keys, so flatten+with_prefix would allow avoiding name conflicts.

@jonasbb
Copy link
Owner

jonasbb commented Jun 27, 2024

I think to do that you would need something like feature(adt_const_params) rust-lang/rust#95174
You need some way to "store" the prefix somehow, but there are no variables to do so. This leaves the option to encode it into the code, which is what the current with_prefix! macro does by generating a specific code snippet for each prefix.

@jonasbb jonasbb closed this as completed Jun 27, 2024
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