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

Add Writer::write_serializable #609

Merged
merged 1 commit into from
Jun 21, 2023
Merged

Conversation

dralley
Copy link
Collaborator

@dralley dralley commented Jun 4, 2023

This introduces a new write_serializable_content method in order to serialize arbitrary types through serde within manual manipulation of an XML writer.

@dralley
Copy link
Collaborator Author

dralley commented Jun 18, 2023

@Mingun Ignore the commit history, I will clean it up (and fix the changelogs, etc.) prior to marking this officially ready for review.

I have left a few open questions on the API. I moved the function from ElementWriter to Writer for all the reasons laid out on the other PR, and because I think it would only add corner cases. For instance, I don't think there is a need to add your own custom attributes on top of what the object would already output during serialization. Do you agree?

I left a few other comments also.

src/se/mod.rs Outdated
&mut self,
indent_char: char,
indent_size: usize,
initial_indent_amt: usize,
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I find this part a bit unsatisfying, I'd rather it be an initial "indent level" that is multiplied by the indent_size to get the initial indent.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Agreed that this would be better.

I think is would be even better to create a new internal method to just set Indent on serializer directly. Then no need to introduce new parameter here.

@codecov-commenter
Copy link

codecov-commenter commented Jun 18, 2023

Codecov Report

Merging #609 (fe20b46) into master (5a536d0) will increase coverage by 0.21%.
The diff coverage is 98.09%.

❗ Your organization is not using the GitHub App Integration. As a result you may experience degraded service beginning May 15th. Please install the Github App Integration for your organization. Read more.

@@            Coverage Diff             @@
##           master     #609      +/-   ##
==========================================
+ Coverage   64.48%   64.69%   +0.21%     
==========================================
  Files          36       36              
  Lines       16921    17014      +93     
==========================================
+ Hits        10911    11007      +96     
+ Misses       6010     6007       -3     
Flag Coverage Δ
unittests 64.69% <98.09%> (+0.21%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
src/writer.rs 92.44% <97.77%> (+3.72%) ⬆️
src/se/content.rs 97.22% <100.00%> (ø)
src/se/element.rs 98.51% <100.00%> (ø)
src/se/mod.rs 92.45% <100.00%> (+0.33%) ⬆️

... and 2 files with indirect coverage changes

src/writer.rs Show resolved Hide resolved
Copy link
Collaborator

@Mingun Mingun left a comment

Choose a reason for hiding this comment

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

I moved the function from ElementWriter to Writer for all the reasons laid out on the other PR, and because I think it would only add corner cases. For instance, I don't think there is a need to add your own custom attributes on top of what the object would already output during serialization. Do you agree?

Yes, this is probably a very niche use case, so the proposed API looks good.

src/writer.rs Show resolved Hide resolved
src/se/mod.rs Outdated
&mut self,
indent_char: char,
indent_size: usize,
initial_indent_amt: usize,
Copy link
Collaborator

Choose a reason for hiding this comment

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

Agreed that this would be better.

I think is would be even better to create a new internal method to just set Indent on serializer directly. Then no need to introduce new parameter here.

@dralley dralley changed the title Implement write_serializable_content on element writer Add Writer::write_serializable Jun 19, 2023
@dralley dralley force-pushed the write-serializable branch 3 times, most recently from 35be8a4 to 3923c63 Compare June 19, 2023 19:33
@dralley dralley requested a review from Mingun June 19, 2023 19:34
@dralley dralley marked this pull request as ready for review June 19, 2023 19:34
@dralley dralley force-pushed the write-serializable branch 4 times, most recently from 0d878c2 to dbd1076 Compare June 19, 2023 22:42
@dralley
Copy link
Collaborator Author

dralley commented Jun 20, 2023

@Mingun Ready

Copy link
Collaborator

@Mingun Mingun left a comment

Choose a reason for hiding this comment

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

Good work. I left some comments on things that I think would be good to have, but nothing blocking.

If you decide to add additional commits, it would be also good to put renaming current_indent_len with documenting fields into its own commit. I like when different things not mixed in one commit

src/writer.rs Outdated Show resolved Hide resolved
src/writer.rs Outdated Show resolved Hide resolved
Changelog.md Outdated Show resolved Hide resolved
src/writer.rs Show resolved Hide resolved
src/writer.rs Outdated Show resolved Hide resolved
src/writer.rs Show resolved Hide resolved
@dralley dralley force-pushed the write-serializable branch 2 times, most recently from 909cd12 to fcdcdf2 Compare June 21, 2023 15:58
Allow serializing individual objects using serde with the raw Writer API

closes tafia#610
@dralley dralley merged commit 0db486f into tafia:master Jun 21, 2023
6 checks passed
@dralley dralley deleted the write-serializable branch June 21, 2023 16:18
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.

None yet

3 participants