Skip to content

Prepare changes to the macro crate.#77

Closed
gibbz00 wants to merge 7 commits into
djc:mainfrom
gibbz00:macro_refactors
Closed

Prepare changes to the macro crate.#77
gibbz00 wants to merge 7 commits into
djc:mainfrom
gibbz00:macro_refactors

Conversation

@gibbz00

@gibbz00 gibbz00 commented Oct 23, 2024

Copy link
Copy Markdown
Contributor

Feedback from djc/instant-epp#56 resulted in the
suggestion of at least 3 new potential macro attributes, (from, into, remote).
Before tackling those, however, I'd like to do some refactors and improvements
to the macro crate. Specifically in terms of making it clearer of when a
attribute belongs to a field, a container; when it is for serialization,
deserialization; and lastly, when it is for named, unnamed, or unit fields of
structs and enums. (There are at least 2 x 2 x 3 = 12 places where attributes
might be valid, not taking into account cases when different attributes are
incompatible with each other.)

Validation is scattered in the codebase, errors are seldom error emitted, and
there's little user documentation to rely on. This PR is the first one in a
series whose goal is to tackle exactly those 3 points. This once splits up some
larger files and uses use crate::*; to improve locality of behavior.

To clarify, this PR changes no behavior whatsoever.

Comment thread instant-xml-macros/src/case.rs
Comment thread instant-xml-macros/src/lib.rs Outdated
Comment thread instant-xml-macros/src/lib.rs Outdated
discard_lifetimes, meta_items, ContainerMeta, FieldMeta, Mode, Namespace, VariantMeta,
};
use crate::meta::{ContainerMeta, FieldMeta, Mode, VariantMeta};

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Nit: no empty line between crate and super imports, please.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

#78

Comment thread instant-xml-macros/src/lib.rs Outdated
de::from_xml(&ast).into()
}

pub(crate) use container::{ContainerMeta, Mode};

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Not a fan of this change. IMO 100-200 line files are a net negative to my ability to understand the code, my optimal size is around 300-800 lines of non-test code.

@gibbz00 gibbz00 Oct 24, 2024

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Understand. For me it's a visibility modifier reason to limit types and their impl blocks to their own module, with quite a few exceptions of course. Easier to reason about them then, and what external libraries each part uses. Save thing as with star imports, ok if i flatten things in the end?

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Similarly to the other aspect, I don't want this right now. If you end up adding substantial logic for one of these types we can definitely consider splitting it out at that point.

Comment thread instant-xml-macros/src/meta/namespace.rs Outdated
Comment thread instant-xml-macros/src/de.rs Outdated
@gibbz00 gibbz00 force-pushed the macro_refactors branch 2 times, most recently from f5ff553 to e5ae0dc Compare October 24, 2024 13:17
@gibbz00 gibbz00 force-pushed the macro_refactors branch 2 times, most recently from cfe4675 to ed7ce1f Compare October 24, 2024 13:31
@@ -0,0 +1,14 @@
mod container;

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

IMO this is still overindexing on small modules. I think it would make sense to move meta.rs to meta/mod.rs, and only split out namespace into a separate file for now.

@djc

djc commented Nov 14, 2024

Copy link
Copy Markdown
Owner

Recreated the commits for cleaning up useless explicit lifetimes in #80, closing this for lack of followup.

@djc djc closed this Nov 14, 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

Successfully merging this pull request may close these issues.

2 participants