Skip to content

Implement a #[jomini(collect_with)] attribute for JominiDeserialize. - #235

Open
jcranmer wants to merge 2 commits into
rakaly:masterfrom
jcranmer:collect_with
Open

Implement a #[jomini(collect_with)] attribute for JominiDeserialize.#235
jcranmer wants to merge 2 commits into
rakaly:masterfrom
jcranmer:collect_with

Conversation

@jcranmer

Copy link
Copy Markdown

This fixes issue #232, although I can't exactly guarantee that performance will be as good as it was before.

I've done some local testing with melted saves via a modified eu4save, using this for collecting trade node data. I haven't done any testing with binary saves, so I can't confirm whether or not it works there.

@nickbabcock nickbabcock left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Heck yeah, super excited!

Comment thread jomini_derive/src/lib.rs Outdated
Comment thread jomini_derive/src/lib.rs
Comment thread jomini_derive/src/lib.rs
Comment thread jomini_derive/src/lib.rs Outdated
#match_arm => Ok(#field_ident)
}
});
let field_enum_match2 = field_enum_match.clone();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Collecting into a vec and then using the same reference seems preferable.

Comment thread jomini_derive/tests/18-collect-with.rs
@jcranmer

Copy link
Copy Markdown
Author

Sorry for the delay in responding to the review comments, I instead got busy, uh, playing the game instead. 😅

Comment thread jomini_derive/src/lib.rs
///
/// - `#[jomini(token=value)]`
///
/// Annoytating all fields with this enables the binary deserializer to map `u16` tokens directly to

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/// Annoytating all fields with this enables the binary deserializer to map `u16` tokens directly to
/// Annotating all fields with this enables the binary deserializer to map `u16` tokens directly to

Comment thread jomini_derive/src/lib.rs
{
match __value {
#(#field_enum_match),* ,
_ => Ok(__Field::__unknown_str(__value.into())),

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure I know what the behavior of this should be for structs that don't have a collect_with, and I'm a little wary of every impl having this extra field and functionality not intended for it.

If there was a cleaner break in impls that have the collectd_with attribute and those without, I'd be comfortable merging this to minimize any potential downsides.

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

Successfully merging this pull request may close these issues.

2 participants